提供商
CredentialInput
重新导出 CredentialInput
CredentialsConfig
重新导出 CredentialsConfig
CredentialsProviderType
EmailConfig
重新导出 EmailConfig
EmailProviderType
重新导出 EmailProviderType
EmailUserConfig
重新导出 EmailUserConfig
AppProvider
在所有 ProviderType 中共享
扩展
属性
callbackUrl
callbackUrl: string;id
id: string;在 AuthConfig.providers 中唯一标识提供商,它也是 URL 的一部分
继承自
name
name: string;默认登录页面登录按钮上使用的提供商名称。例如,如果它为“Google”,则相应的按钮将显示为:“使用 Google 登录”
继承自
signinUrl
signinUrl: string;type
type: ProviderType;参见 ProviderType
继承自
CommonProviderOptions
在所有 ProviderType 中共享
扩展自
属性
id
id: string;在 AuthConfig.providers 中唯一标识提供商,它也是 URL 的一部分
name
name: string;默认登录页面登录按钮上使用的提供商名称。例如,如果它为“Google”,则相应的按钮将显示为:“使用 Google 登录”
type
type: ProviderType;参见 ProviderType
OAuth2Config<Profile>
待办:文档
扩展
CommonProviderOptions.PartialIssuer
类型参数
| 类型参数 |
|---|
Profile |
属性
[conformInternal]?
optional [conformInternal]: true;参见
customFetch?
optional [customFetch]: (input, init?) => Promise<Response>;参见
参数
| 参数 | 类型 |
|---|---|
input | URL | RequestInfo |
init? | RequestInit |
返回
account?
optional account: AccountCallback;接收 OAuth 提供商返回的完整TokenSet,并返回一个子集。它用于创建与数据库中用户关联的帐户。
默认值为:access_token, id_token, refresh_token, expires_at, scope, token_type, session_state
示例
import GitHub from "@auth/core/providers/github"
// ...
GitHub({
account(account) {
// https://githubdocs.cn/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens#refreshing-a-user-access-token-with-a-refresh-token
const refresh_token_expires_at =
Math.floor(Date.now() / 1000) + Number(account.refresh_token_expires_in)
return {
access_token: account.access_token,
expires_at: account.expires_at,
refresh_token: account.refresh_token,
refresh_token_expires_at
}
}
})参见
- 数据库适配器:帐户模型
- https://openid.net/specs/openid-connect-core-1_0.html#TokenResponse
- https://www.ietf.org/rfc/rfc6749.html#section-5.1
allowDangerousEmailAccountLinking?
optional allowDangerousEmailAccountLinking: boolean;通常,当您使用 OAuth 提供商登录并且具有相同电子邮件地址的另一个帐户已存在时,这些帐户不会自动链接。
登录时的自动帐户链接在任意提供商之间并不安全,默认情况下已禁用。在我们的安全常见问题解答中了解更多信息。
但是,如果您相信相关提供商已安全地验证了与帐户关联的电子邮件地址,则可能需要允许自动帐户链接。设置allowDangerousEmailAccountLinking: true以启用自动帐户链接。
authorization?
optional authorization: string | AuthorizationEndpointHandler;登录过程将通过将用户发送到此 URL 来启动。
checks?
optional checks: ("none" | "state" | "pkce")[];在回调端点上执行的 CSRF 保护。
默认
["pkce"]注意
当redirectProxyUrl或AuthConfig.redirectProxyUrl设置时,"state"将自动添加到检查中。
RFC 7636 - OAuth 公共客户端代码交换证明密钥 (PKCE) | RFC 6749 - OAuth 2.0 授权框架 | OpenID Connect Core 1.0 |
client?
optional client: Partial<Client & {
token_endpoint_auth_method: string;
}>;将覆盖传递给底层的 OAuth 库。有关详细信息,请参见oauth4webapi 客户端。
clientId?
optional clientId: string;clientSecret?
optional clientSecret: string;id
id: string;当您想登录到特定提供商时,标识该提供商。
示例
signIn('github') // "github" is the provider ID覆盖
issuer?
optional issuer: string;覆盖
PartialIssuer.issuer
jwks_endpoint
jwks_endpoint: any;继承自
PartialIssuer.jwks_endpoint
name
name: string;提供商的名称。显示在默认登录页面上。
覆盖
options?
optional options: OAuthUserConfig<Profile>;profile?
optional profile: ProfileCallback<Profile>;接收 OAuth 提供商返回的完整Profile,并返回一个子集。它用于在数据库中创建用户。
默认值为:id, email, name, image
参见
redirectProxyUrl?
optional redirectProxyUrl: string;style?
optional style: OAuthProviderButtonStyles;token?
optional token: string | TokenEndpointHandler;type
type: "oauth";参见 ProviderType
覆盖
userinfo?
optional userinfo: string | UserinfoEndpointHandler;wellKnown?
optional wellKnown: string;符合 OpenID Connect (OIDC) 标准的提供商可以配置此选项而不是authorize/token/userinfo选项,在大多数情况下无需进一步配置。您仍然可以使用authorize/token/userinfo选项进行高级控制。
OAuthProviderButtonStyles
属性
bg?
optional bg: string;已弃用
请改用 ‘brandColor’
brandColor?
optional brandColor: string;logo?
optional logo: string;text?
optional text: string;已弃用
OIDCConfig<Profile>
OAuth2Config 的扩展。
参见
https://openid.net/specs/openid-connect-core-1_0.html
扩展
Omit<OAuth2Config<Profile>,"type"|"checks">
类型参数
| 类型参数 |
|---|
Profile |
属性
[conformInternal]?
optional [conformInternal]: true;参见
继承自
Omit.[conformInternal]
customFetch?
optional [customFetch]: (input, init?) => Promise<Response>;参见
参数
| 参数 | 类型 |
|---|---|
input | URL | RequestInfo |
init? | RequestInit |
返回
继承自
Omit.[customFetch]
account?
optional account: AccountCallback;接收 OAuth 提供商返回的完整TokenSet,并返回一个子集。它用于创建与数据库中用户关联的帐户。
默认值为:access_token, id_token, refresh_token, expires_at, scope, token_type, session_state
示例
import GitHub from "@auth/core/providers/github"
// ...
GitHub({
account(account) {
// https://githubdocs.cn/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens#refreshing-a-user-access-token-with-a-refresh-token
const refresh_token_expires_at =
Math.floor(Date.now() / 1000) + Number(account.refresh_token_expires_in)
return {
access_token: account.access_token,
expires_at: account.expires_at,
refresh_token: account.refresh_token,
refresh_token_expires_at
}
}
})参见
- 数据库适配器:帐户模型
- https://openid.net/specs/openid-connect-core-1_0.html#TokenResponse
- https://www.ietf.org/rfc/rfc6749.html#section-5.1
继承自
Omit.account
allowDangerousEmailAccountLinking?
optional allowDangerousEmailAccountLinking: boolean;通常,当您使用 OAuth 提供商登录并且具有相同电子邮件地址的另一个帐户已存在时,这些帐户不会自动链接。
登录时的自动帐户链接在任意提供商之间并不安全,默认情况下已禁用。在我们的安全常见问题解答中了解更多信息。
但是,如果您相信相关提供商已安全地验证了与帐户关联的电子邮件地址,则可能需要允许自动帐户链接。设置allowDangerousEmailAccountLinking: true以启用自动帐户链接。
继承自
Omit.allowDangerousEmailAccountLinking
authorization?
optional authorization: string | AuthorizationEndpointHandler;登录过程将通过将用户发送到此 URL 来启动。
继承自
Omit.authorization
checks?
optional checks: ("none" | "state" | "nonce" | "pkce")[];client?
optional client: Partial<Client & {
token_endpoint_auth_method: string;
}>;将覆盖传递给底层的 OAuth 库。有关详细信息,请参见oauth4webapi 客户端。
继承自
Omit.client
clientId?
optional clientId: string;继承自
Omit.clientId
clientSecret?
optional clientSecret: string;继承自
Omit.clientSecret
id
id: string;当您想登录到特定提供商时,标识该提供商。
示例
signIn('github') // "github" is the provider ID继承自
忽略.id
idToken?
optional idToken: boolean;如果设置为 false,则将为用户数据获取 userinfo_endpoint。
注意
在授权流程期间,仍然需要返回 id_token。
issuer?
optional issuer: string;继承自
忽略.issuer
jwks_endpoint
jwks_endpoint: any;继承自
忽略.jwks_endpoint
name
name: string;提供商的名称。显示在默认登录页面上。
继承自
忽略.name
options?
optional options: OAuthUserConfig<Profile>;继承自
忽略.options
profile?
optional profile: ProfileCallback<Profile>;接收 OAuth 提供商返回的完整Profile,并返回一个子集。它用于在数据库中创建用户。
默认值为:id, email, name, image
参见
继承自
忽略.profile
redirectProxyUrl?
optional redirectProxyUrl: string;继承自
忽略.redirectProxyUrl
style?
optional style: OAuthProviderButtonStyles;继承自
忽略.style
token?
optional token: string | TokenEndpointHandler;继承自
忽略.token
type
type: "oidc";userinfo?
optional userinfo: string | UserinfoEndpointHandler;继承自
忽略.userinfo
wellKnown?
optional wellKnown: string;符合 OpenID Connect (OIDC) 标准的提供商可以配置此选项而不是authorize/token/userinfo选项,在大多数情况下无需进一步配置。您仍然可以使用authorize/token/userinfo选项进行高级控制。
继承自
忽略.wellKnown
AccountCallback()
type AccountCallback: (tokens) => TokenSet | undefined | void;参数
| 参数 | 类型 |
|---|---|
tokens | TokenSet |
返回值
TokenSet | undefined | void
AppProviders
type AppProviders: (Provider | ReturnType<BuiltInProviders[keyof BuiltInProviders]>)[];AuthorizationEndpointHandler
type AuthorizationEndpointHandler: EndpointHandler<AuthorizationParameters>;BuiltInProviderType
type BuiltInProviderType: RedirectableProviderType | OAuthProviderType | WebAuthnProviderType;BuiltInProviders
type BuiltInProviders: Record<OAuthProviderType, (config) => OAuthConfig<any>> & Record<CredentialsProviderType, typeof default> & Record<EmailProviderType, typeof default> & Record<WebAuthnProviderType, (config) => WebAuthnConfig>;OAuthChecks
type OAuthChecks: OpenIDCallbackChecks | OAuthCallbackChecks;OAuthConfig<Profile>
type OAuthConfig<Profile>: OIDCConfig<Profile> | OAuth2Config<Profile>;类型参数
| 类型参数 |
|---|
Profile |
OAuthEndpointType
type OAuthEndpointType: "authorization" | "token" | "userinfo";OAuthProviderType
type OAuthProviderType:
| "42-school"
| "apple"
| "asgardeo"
| "atlassian"
| "auth0"
| "authentik"
| "azure-ad-b2c"
| "azure-ad"
| "azure-devops"
| "bankid-no"
| "battlenet"
| "beyondidentity"
| "box"
| "boxyhq-saml"
| "bungie"
| "click-up"
| "cognito"
| "coinbase"
| "concept2"
| "descope"
| "discord"
| "dribbble"
| "dropbox"
| "duende-identity-server6"
| "eventbrite"
| "eveonline"
| "facebook"
| "faceit"
| "forwardemail"
| "foursquare"
| "freshbooks"
| "fusionauth"
| "github"
| "gitlab"
| "google"
| "hubspot"
| "identity-server4"
| "instagram"
| "kakao"
| "keycloak"
| "kinde"
| "line"
| "linkedin"
| "mailchimp"
| "mailgun"
| "mailru"
| "mastodon"
| "mattermost"
| "medium"
| "microsoft-entra-id"
| "naver"
| "netlify"
| "netsuite"
| "nextcloud"
| "nodemailer"
| "notion"
| "okta"
| "onelogin"
| "ory-hydra"
| "osso"
| "osu"
| "passage"
| "passkey"
| "patreon"
| "ping-id"
| "pinterest"
| "pipedrive"
| "postmark"
| "reddit"
| "resend"
| "roblox"
| "salesforce"
| "sendgrid"
| "simplelogin"
| "slack"
| "spotify"
| "strava"
| "threads"
| "tiktok"
| "todoist"
| "trakt"
| "twitch"
| "twitter"
| "united-effects"
| "vipps"
| "vk"
| "webauthn"
| "webex"
| "wechat"
| "wikimedia"
| "wordpress"
| "workos"
| "yandex"
| "zitadel"
| "zoho"
| "zoom";OAuthUserConfig<Profile>
type OAuthUserConfig<Profile>: Omit<Partial<OAuthConfig<Profile>>, "options" | "type">;类型参数
| 类型参数 |
|---|
Profile |
OIDCConfigInternal<Profile>
type OIDCConfigInternal<Profile>: OAuthConfigInternal<Profile> & {
checks: OIDCConfig<Profile>["checks"];
idToken: OIDCConfig<Profile>["idToken"];
};类型声明
checks
checks: OIDCConfig<Profile>["checks"];idToken
idToken: OIDCConfig<Profile>["idToken"];类型参数
| 类型参数 |
|---|
Profile |
OIDCUserConfig<Profile>
type OIDCUserConfig<Profile>: Omit<Partial<OIDCConfig<Profile>>, "options" | "type">;类型参数
| 类型参数 |
|---|
Profile |
ProfileCallback()<Profile>
type ProfileCallback<Profile>: (profile, tokens) => Awaitable<User>;类型参数
| 类型参数 |
|---|
Profile |
参数
| 参数 | 类型 |
|---|---|
profile | Profile |
tokens | TokenSet |
返回值
Provider<P>
type Provider<P>:
| OIDCConfig<P>
| OAuth2Config<P>
| EmailConfig
| CredentialsConfig
| WebAuthnConfig & InternalProviderOptions | (...args) =>
| OAuth2Config<P>
| OIDCConfig<P>
| EmailConfig
| CredentialsConfig
| WebAuthnConfig & InternalProviderOptions & InternalProviderOptions;必须是支持的身份验证提供程序配置
- OAuthConfig
- EmailConfigInternal
- CredentialsConfigInternal
有关更多信息,请参阅指南
参见
类型参数
| 类型参数 | 值 |
|---|---|
P 扩展 Profile | 任何 |
ProviderType
type ProviderType:
| "oidc"
| "oauth"
| "email"
| "credentials"
| WebAuthnProviderType;传递给 Auth.js 的提供程序必须定义这些类型之一。
参见
RedirectableProviderType
type RedirectableProviderType: "email" | "credentials";TokenEndpointHandler
type TokenEndpointHandler: EndpointHandler<UrlParams, {
checks: OAuthChecks;
params: CallbackParamsType;
}, {
tokens: TokenSet;
}>;UserinfoEndpointHandler
type UserinfoEndpointHandler: EndpointHandler<UrlParams, {
tokens: TokenSet;
}, Profile>;