mirror of
https://github.com/better-auth/better-auth.git
synced 2026-08-02 11:03:49 -05:00
feat(generic-oauth): verify discovery id_tokens and enable id_token sign-in (#9966)
This commit is contained in:
@@ -75,6 +75,21 @@ The `scopes` parameter is additive: appended to the provider's configured scopes
|
||||
|
||||
You can also pass `additionalData` (a `Record<string, any>`) to round-trip client data through the flow; read it back on the callback with `getOAuthState()` and treat it as untrusted. See [Passing Additional Data Through OAuth Flow](/docs/concepts/oauth#passing-additional-data-through-oauth-flow).
|
||||
|
||||
### Sign In with an ID Token
|
||||
|
||||
Providers configured with a `discoveryUrl` whose discovery document publishes a `jwks_uri` also accept a client-obtained `id_token` directly, skipping the redirect flow. The token is verified against the provider's JWKS before any claims are trusted:
|
||||
|
||||
```ts
|
||||
await authClient.signIn.social({
|
||||
provider: "provider-id",
|
||||
idToken: {
|
||||
token: idTokenFromProvider,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
Providers configured with explicit endpoints instead of `discoveryUrl` do not support this path and return `ID_TOKEN_NOT_SUPPORTED`.
|
||||
|
||||
### Link Account
|
||||
|
||||
```ts
|
||||
@@ -282,7 +297,7 @@ interface GenericOAuthConfig {
|
||||
|
||||
**providerId**: A unique string to identify the OAuth provider configuration.
|
||||
|
||||
**discoveryUrl**: (Optional) URL to fetch the provider's OAuth 2.0/OIDC configuration. If provided, endpoints like `authorizationUrl`, `tokenUrl`, and `userInfoUrl` will be auto-discovered at server startup.
|
||||
**discoveryUrl**: (Optional) URL to fetch the provider's OAuth 2.0/OIDC configuration. If provided, endpoints like `authorizationUrl`, `tokenUrl`, and `userInfoUrl` will be auto-discovered at server startup. When the discovery document publishes a `jwks_uri`, `id_token`s returned by the provider are verified against it (signature, issuer, audience, and advertised signing algorithms) before their claims are used; a token that fails verification rejects the sign-in.
|
||||
|
||||
**authorizationUrl**: (Optional) The OAuth provider's authorization endpoint. Not required if using `discoveryUrl`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user