Skip to content

Commit 4b8d5f5

Browse files
hfcmathesoncharislam
authored
docs: add workos tpa docs (supabase#36662)
* docs: add workos to 3rd party auth docs * Commit @charislam's suggestions Co-authored-by: Charis <[email protected]> * more explanation of the user_role claim * drop CLI instructions for now * add WorkOS to nav menu * fix typo * use issuer not client id * fix prettier --------- Co-authored-by: Cameron Matheson <[email protected]> Co-authored-by: Cameron Matheson <[email protected]> Co-authored-by: Charis <[email protected]>
1 parent 226d05f commit 4b8d5f5

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ export const auth = {
663663
{ name: 'Firebase Auth', url: '/guides/auth/third-party/firebase-auth' },
664664
{ name: 'Auth0', url: '/guides/auth/third-party/auth0' },
665665
{ name: 'AWS Cognito (Amplify)', url: '/guides/auth/third-party/aws-cognito' },
666+
{ name: 'WorkOS', url: '/guides/auth/third-party/workos' },
666667
],
667668
},
668669
{

apps/docs/content/guides/auth/third-party/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Supabase has first-class support for these third-party authentication providers:
1010
- [Firebase Auth](/docs/guides/auth/third-party/firebase-auth)
1111
- [Auth0](/docs/guides/auth/third-party/auth0)
1212
- [AWS Cognito (with or without AWS Amplify)](/docs/guides/auth/third-party/aws-cognito)
13+
- [WorkOS](/docs/guides/auth/third-party/workos)
1314

1415
You can use these providers alongside Supabase Auth, or on their own, to access the [Data API (REST and GraphQL)](/docs/guides/database), [Storage](/docs/guides/storage), [Realtime](/docs/guides/storage) and [Functions](/docs/guides/functions) from your existing apps.
1516

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
id: 'auth-third-party-workos'
3+
title: 'WorkOS'
4+
subtitle: 'Use WorkOS with your Supabase project'
5+
---
6+
7+
WorkOS can be used as a third-party authentication provider alongside Supabase Auth, or standalone, with your Supabase project.
8+
9+
## Getting started
10+
11+
1. First you need to add an integration to connect your Supabase project with your WorkOS tenant. You will need your WorkOS issuer. The issuer is `https://api.workos.com/user_management/<your-client-id>`. Substitute your [custom auth domain](https://workos.com/docs/custom-domains/auth-api) for "api.workos.com" if configured.
12+
2. Add a new Third-party Auth integration in your project's [Authentication settings](/dashboard/project/_/settings/auth).
13+
3. Set up a JWT template to assign the `role: 'authenticated'` claim to your access token.
14+
15+
## Setup the Supabase client library
16+
17+
<Tabs type="underlined" queryGroup="language">
18+
19+
<TabPanel id="ts" label="TypeScript">
20+
21+
```typescript
22+
import { createClient } from '@supabase/supabase-js'
23+
import { createClient as createAuthKitClient } from '@workos-inc/authkit-js'
24+
25+
const authkit = await createAuthKitClient('WORKOS_CLIENT_ID', {
26+
apiHostname: '<WORKOS_AUTH_DOMAIN>',
27+
})
28+
29+
const supabase = createClient('https://<supabase-project>.supabase.co', 'SUPABASE_ANON_KEY', {
30+
accessToken: async () => {
31+
return authkit.getAccessToken()
32+
},
33+
})
34+
```
35+
36+
</TabPanel>
37+
38+
</Tabs>
39+
40+
## Add a new Third-Party Auth integration to your project
41+
42+
In the dashboard navigate to your project's [Authentication settings](/dashboard/project/_/settings/auth) and find the Third-Party Auth section to add a new integration.
43+
44+
## Set up a JWT template to add the authenticated role.
45+
46+
Your Supabase project inspects the `role` claim present in all JWTs sent to it, to assign the correct Postgres role when using the Data API, Storage or Realtime authorization.
47+
48+
WorkOS JWTs already contain a `role` claim that corresponds to the user's role in their organization. It is necessary to adjust the `role` claim to be `"authenticated"` like Supabase expects. This can be done using JWT templates (navigate to Authentication -> Sessions -> JWT Template in the WorkOS Dashboard).
49+
50+
This template overrides the `role` claim to meet Supabase's expectations, and adds the WorkOS role in a new `user_role` claim:
51+
52+
```json
53+
{
54+
"role": "authenticated",
55+
"user_role": {{organization_membership.role}}
56+
}
57+
```

0 commit comments

Comments
 (0)