{"record":{"id":"e9bf7de289ab176e","repo":"toeverything/AFFiNE","slug":"unknown-oauth-provider-e9bf7d","errorCode":"unknown_oauth_provider","errorMessage":"Unknown authentication provider ${name}.","messagePattern":"Unknown authentication provider (.+?)\\.","errorType":"exception","errorClass":"UnknownOauthProvider","httpStatus":400,"severity":"error","filePath":"packages/backend/server/src/plugins/oauth/controller.ts","lineNumber":57,"sourceCode":"  @UseNamedGuard('version')\n  @Post('/preflight')\n  @HttpCode(HttpStatus.OK)\n  async preflight(@Req() req: Request, @Body() body?: unknown) {\n    const input = OAuthPreflightBodySchema.safeParse(body);\n    if (!input.success) {\n      const fields = new Set(input.error.issues.map(issue => issue.path[0]));\n      if (fields.has('client_nonce')) {\n        throw new MissingOauthQueryParameter({ name: 'client_nonce' });\n      }\n      if (fields.has('client')) {\n        throw new ActionForbidden();\n      }\n      if (fields.has('provider')) {\n        const provider =\n          body && typeof body === 'object' && 'provider' in body\n            ? String(body.provider)\n            : '';\n        throw new UnknownOauthProvider({ name: provider });\n      }\n      throw new MissingOauthQueryParameter({ name: 'provider' });\n    }\n\n    const {\n      provider: unknownProviderName,\n      redirect_uri: redirectUri,\n      client,\n      client_nonce: clientNonce,\n    } = input.data;\n\n    const providerName =\n      OAuthProviderName[unknownProviderName as keyof typeof OAuthProviderName];\n    const provider = this.providerFactory.get(providerName);\n\n    if (!provider) {\n      throw new UnknownOauthProvider({ name: unknownProviderName });\n    }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/591f874dad30887a80143a061a44bd3ca7ee3299/packages/backend/server/src/plugins/oauth/controller.ts#L39-L75","documentation":"POST /oauth/preflight throws UnknownOauthProvider at the schema-validation branch when the `provider` field itself fails the OAuthProviderSchema enum ('Google', 'GitHub', 'Apple', 'OIDC'). The thrown name is derived by stringifying whatever was sent, so the error message echoes your invalid input. This fires before the provider registry is even consulted.","triggerScenarios":"Preflight body with provider outside the enum or wrong casing: 'google', 'github', 'oidc', 'Facebook', 'Microsoft', or provider missing entirely (issue path 'provider'). The name in the message will be String(body.provider) — often 'undefined' when the field is absent.","commonSituations":"Integrating a provider AFFiNE doesn't support natively (use OIDC generic provider for those); case-sensitive enum catching lowercase names; frontend dropdown storing lowercase keys.","solutions":["Use an exact enum value with exact casing: 'Google', 'GitHub', 'Apple', or 'OIDC'","For any other IdP (Keycloak, Okta, Azure AD, Casdoor...), configure the server's generic OIDC provider and send provider: 'OIDC'","Check the error's name field — it echoes exactly what you sent, which pinpoints the casing/value bug"],"exampleFix":"// before\n{ provider: 'google', client: 'web', client_nonce: nonce }\n\n// after\n{ provider: 'Google', client: 'web', client_nonce: nonce }","handlingStrategy":"validation","validationCode":"const PROVIDERS = ['Google', 'GitHub', 'Apple', 'OIDC'] as const;\nif (!PROVIDERS.includes(provider)) {\n  throw new Error(`provider must be one of ${PROVIDERS.join(', ')} (case-sensitive); use 'OIDC' for generic providers`);\n}","typeGuard":"type ProviderName = 'Google' | 'GitHub' | 'Apple' | 'OIDC';\nfunction isProviderName(p: unknown): p is ProviderName {\n  return typeof p === 'string' && ['Google', 'GitHub', 'Apple', 'OIDC'].includes(p);\n}","tryCatchPattern":"try { await post('/oauth/preflight', body); } catch (e) {\n  if ((e as any).code === 'unknown_oauth_provider') {\n    // e.args.name echoes exactly what we sent — compare against the enum to find the typo\n    throw new Error(`Unknown provider '${(e as any).args.name}'; expected one of Google|GitHub|Apple|OIDC`);\n  }\n  throw e;\n}","preventionTips":["Use a union type / enum for provider names in client code — casing is significant ('Google', not 'google')","For any IdP outside the big three, configure and select 'OIDC' rather than expecting native support","The error message echoes your input verbatim; read it to spot casing and spelling bugs fast"],"tags":["oauth","preflight","provider","enum","validation"],"backgroundTag":"unsupported-auth-provider","analyzedSha":"591f874dad30887a80143a061a44bd3ca7ee3299","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}