providers
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://docs.github.com/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"
將會自動新增至 checks。
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://docs.github.com/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
授權?
optional authorization: string | AuthorizationEndpointHandler;
將使用者導向此 URL 以啟動登入流程。
繼承自
Omit.authorization
檢查?
optional checks: ("none" | "state" | "nonce" | "pkce")[];
客戶端?
optional client: Partial<Client & {
token_endpoint_auth_method: string;
}>;
將覆寫傳遞至底層的 OAuth 函式庫。請參閱 oauth4webapi
用戶端 以取得詳細資訊。
繼承自
Omit.client
客戶端 ID?
optional clientId: string;
繼承自
Omit.clientId
客戶端密鑰?
optional clientSecret: string;
繼承自
Omit.clientSecret
ID
id: string;
當您想要登入特定供應商時,識別該供應商。
範例
signIn('github') // "github" is the provider ID
繼承自
Omit.id
ID Token?
optional idToken: boolean;
如果設定為 false
,將會提取 userinfo_endpoint
來取得使用者資料。
注意
在授權流程中仍然需要返回一個 id_token
。
發行者?
optional issuer: string;
繼承自
Omit.issuer
jwks_endpoint
jwks_endpoint: any;
繼承自
Omit.jwks_endpoint
名稱
name: string;
供應商的名稱。顯示在預設登入頁面上。
繼承自
Omit.name
選項?
optional options: OAuthUserConfig<Profile>;
繼承自
Omit.options
個人資料?
optional profile: ProfileCallback<Profile>;
接收 OAuth 供應商回傳的完整 Profile,並回傳子集。它用於在資料庫中建立使用者。
預設值:id
、email
、name
、image
參閱
繼承自
Omit.profile
重導代理 URL?
optional redirectProxyUrl: string;
繼承自
Omit.redirectProxyUrl
樣式?
optional style: OAuthProviderButtonStyles;
繼承自
Omit.style
Token?
optional token: string | TokenEndpointHandler;
繼承自
Omit.token
類型
type: "oidc";
使用者資訊?
optional userinfo: string | UserinfoEndpointHandler;
繼承自
Omit.userinfo
Well-known?
optional wellKnown: string;
符合 OpenID Connect (OIDC) 的供應商可以設定此選項,而無需在大多數情況下進一步設定 authorize
/token
/userinfo
選項。您仍然可以使用 authorize
/token
/userinfo
選項進行進階控制。
繼承自
Omit.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: 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 | any |
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>;