工作操作系统
Use WorkOS with your Supabase project
WorkOS 可以和 Supabase Auth 一起作为第三方身份验证提供商使用,也可以作为独立服务与你的 Supabase 项目配合使用。
🌐 WorkOS can be used as a third-party authentication provider alongside Supabase Auth, or standalone, with your Supabase project.
入门 #
🌐 Getting started
- 首先,你需要添加一个集成,将你的 Supabase 项目与你的 WorkOS 租户连接起来。你需要你的 WorkOS 发行者。发行者是
https://api.workos.com/user_management/<your-client-id>。如果已配置,请将你的自定义认证域替换掉“api.workos.com”。 - 在你项目的身份验证设置中添加一个新的第三方认证集成。
- 设置一个 JWT 模板,将
role: 'authenticated'声明分配给你的访问令牌。
设置 Supabase 客户端库 #
🌐 Setup the Supabase client library
1import { createClient } from '@supabase/supabase-js'2import { createClient as createAuthKitClient } from '@workos-inc/authkit-js'34const authkit = await createAuthKitClient('WORKOS_CLIENT_ID', {5 apiHostname: '<WORKOS_AUTH_DOMAIN>',6})78const supabase = createClient(9 'https://<supabase-project>.supabase.co',10 'SUPABASE_PUBLISHABLE_KEY',11 {12 accessToken: async () => {13 return authkit.getAccessToken()14 },15 }16)在你的项目中添加一个新的第三方认证集成 #
🌐 Add a new Third-Party Auth integration to your project
在仪表板中,进入你项目的 身份验证设置,找到第三方认证部分,添加一个新的集成。
🌐 In the dashboard navigate to your project's Authentication settings and find the Third-Party Auth section to add a new integration.
设置一个 JWT 模板来添加已认证的角色。 #
🌐 Set up a JWT template to add the authenticated role.
你的 Supabase 项目会检查所有发送给它的 JWT 中的 role 声明,以便在使用 Data API、Storage 或 Realtime 授权时分配正确的 Postgres 角色。
🌐 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.
WorkOS 的 JWT 已经包含一个 role 声明,对应用户在组织中的角色。需要将 role 声明调整为 "authenticated",以符合 Supabase 的要求。这可以通过 JWT 模板来完成(在 WorkOS 控制面板中导航到 Authentication -> Sessions -> JWT Template)。
🌐 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).
此模板覆盖了 role 声明以符合 Supabase 的要求,并在新的 user_role 声明中添加了 WorkOS 角色:
🌐 This template overrides the role claim to meet Supabase's expectations, and adds the WorkOS role in a new user_role claim:
1{2 "role": "authenticated",3 "user_role": {{organization_membership.role}}4}