跳转到主要内容
FIM One 支持通过 GitHub、Google、Discord 和 Feishu(Lark)进行社交登录。任何在环境中存在凭证的提供商都会在登录页面上自动显示登录按钮 — 无需更改代码。 回调 URL 模式 — 在每个提供商的开发者控制台中注册此确切 URL:
API_BASE_URL 是 FIM One 后端的外部可访问地址。示例:

GitHub

Developer console: https://github.com/settings/developers
  1. Click OAuth Apps → New OAuth App.
  2. Fill in:
    • Application name — any name (e.g. FIM One)
    • Homepage URL — your frontend URL (e.g. https://yourdomain.com)
    • Authorization callback URL — https://yourdomain.com/api/auth/oauth/github/callback
  3. Click Register application, then click Generate a new client secret.
  4. Copy the Client ID and the generated Client Secret into your .env.
Scopes requested automatically: read:user, user:email GitHub accounts with a private primary email are handled correctly — FIM One fetches the primary email from /user/emails (not the public profile email) and records whether GitHub marks it verified.

Google

开发者控制台: https://console.cloud.google.com/apis/credentials
  1. 点击 + CREATE CREDENTIALS → OAuth client ID。
  2. 如果出现提示,先配置 OAuth consent screen(将 User Type 设置为”External”以用于个人/公共应用)。
  3. 将 Application type 设置为 Web application。
  4. 在 Authorized redirect URIs 下,添加:
  5. 点击 Create,然后复制 Client ID 和 Client Secret。
自动请求的作用域: openid, email, profile
注意:在开发期间,同意屏幕将显示”This app is not verified”警告。您可以继续通过它进行测试。如果要为最终用户移除该警告,请发布同意屏幕。

Discord

开发者控制台: https://discord.com/developers/applications
  1. 点击 New Application 并给它命名。
  2. 在左侧边栏中,点击 OAuth2。
  3. 在 Redirects 下,点击 Add Redirect 并输入:
  4. 复制 Client ID(显示在 OAuth2 页面顶部)并点击 Reset Secret 以显示 Client Secret。
自动请求的作用域: identify, email
Discord 不保证所有账户都有已验证的电子邮件。如果用户未向 Discord 验证其电子邮件,email 字段可能为 null。FIM One 在这种情况下会使用 null 电子邮件创建账户 — 用户可以稍后在设置中添加。

飞书 (Lark)

仅限租户范围。 飞书自建应用只能对创建该应用的同一企业租户内的用户进行身份验证。来自其他飞书租户的用户将看到”无权限”错误。这意味着飞书 OAuth 不适合公共 SaaS 部署,其中用户来自不同的组织。它适用于私有/单组织部署,其中所有用户属于同一飞书租户。要支持跨租户飞书登录,您需要将应用发布到飞书应用商店并通过飞书的审核流程——这很复杂且要求严格。
开发者控制台: https://open.feishu.cn/app
  1. 点击创建应用 → 自建应用。需要公司/企业账户——飞书 OAuth 不适用于个人账户。
  2. 在权限与范围下,搜索并启用:
    • contact:user.email:readonly
  3. 在安全设置 → 重定向 URL 下,添加您的回调 URL:
  4. 从凭证与基本信息部分复制 App ID 和 App Secret。
在控制台中配置的范围(不在授权 URL 中): contact:user.email:readonly
注意:飞书使用 App ID / App Secret 而不是标准的 Client ID / Client Secret 命名。环境变量名称反映了这一点:FEISHU_APP_ID 和 FEISHU_APP_SECRET。

Important: Feishu Email Behavior

The Feishu user info API (authen/v1/user_info) returns an email and an enterprise contact email (联系邮箱, enterprise_email) — the address configured by the organization admin in the Feishu admin console. FIM One reads email first, then enterprise_email. The address counts as verified only when it is the enterprise email of a tenant listed in FEISHU_TRUSTED_TENANT_KEYS. Consequences:
  • Users whose org admin has not configured a contact email will get an empty email field from the API, even though they have a valid Feishu account.
  • Users on personal Feishu accounts (not part of an enterprise) will always get an empty email.
FIM One handles this gracefully: see Account Binding Rules below.

账户绑定规则

注册用户可以从设置 → 账户链接其他 OAuth 提供商。当用户启动绑定时,以下规则适用:

Linking from Settings (all providers)

Linking needs a full sign-in: a session that has passed two-factor authentication where it is enabled. API keys and the temporary 2FA token cannot link a provider.
  • Both sides have an email → the email returned by the provider must match the FIM account’s email. This prevents accidentally linking another person’s social account to your FIM account. A mismatch is rejected with an email_mismatch error.
  • Either side has no email (the provider returned none, or the FIM account has no email) → binding succeeds on the signed-in session alone. In practice this affects Feishu accounts without an enterprise email and some Discord accounts.

First sign-in with a provider (no binding yet)

When a user signs in through a provider that is not linked to any account yet:
  1. FIM One looks for an existing account with the same email. The match is used only when the address is verified on both sides: the provider reports it as verified, and the existing account’s email is verified. For Feishu, “verified” means the enterprise email of a tenant listed in FEISHU_TRUSTED_TENANT_KEYS.
  2. If a match is found, the provider is linked to that existing FIM account and the user is logged in.
  3. Otherwise a new FIM account is created with whatever email the provider returned (none, if it returned none). This is refused with registration_disabled when registration is disabled or invite-only.
When is an account’s email verified? When it was registered with the emailed verification code (email_verification_enabled on and SMTP configured), when an administrator created it, when it is the first account of the installation, or when it was created by a provider sign-in whose provider reported the address as verified. An account registered with an email and a password on a deployment that does not send verification codes holds an unverified address: a provider sign-in for that address is not linked to it and creates a separate account instead, so two accounts can then hold the same address. A password signs in to the account it was set on; an emailed sign-in or reset code goes to the account whose address is verified. To use one account with both, sign in with the password first and link the provider under Settings → Account, instead of using the provider’s button on the sign-in page. If the matched or linked account has two-factor authentication enabled, the sign-in stops at the 2FA step before a session is issued.

Environment Variables Quick Reference

“Required: Both” means both the _ID and _SECRET (or _APP_ID and _APP_SECRET for Feishu) must be set together; setting only one has no effect.
See Environment Variables for full documentation of FRONTEND_URL, API_BASE_URL, and NEXT_PUBLIC_API_URL.