跳至內容
從 NextAuth.js v4 遷移?請閱讀 我們的遷移指南.

providers

CredentialInput

重新導出 CredentialInput

CredentialsConfig

重新導出 CredentialsConfig

CredentialsProviderType

重新導出 CredentialsProviderType

EmailConfig

重新導出 EmailConfig

EmailProviderType

重新導出 EmailProviderType

EmailUserConfig

重新導出 EmailUserConfig

AppProvider

在所有 ProviderType 中共用

繼承自

屬性

callbackUrl

callbackUrl: string;

id

id: string;

在 AuthConfig.providers 中唯一識別供應商。它也是 URL 的一部分

繼承自

CommonProviderOptions.id

name

name: string;

預設登入頁面的登入按鈕上使用的供應商名稱。例如,如果是「Google」,則對應的按鈕會顯示:「使用 Google 登入」

繼承自

CommonProviderOptions.name

signinUrl

signinUrl: string;

type

type: ProviderType;

參見 ProviderType

繼承自

CommonProviderOptions.type


CommonProviderOptions

在所有 ProviderType 中共用

擴展自

屬性

id

id: string;

在 AuthConfig.providers 中唯一識別供應商。它也是 URL 的一部分

name

name: string;

預設登入頁面的登入按鈕上使用的供應商名稱。例如,如果是「Google」,則對應的按鈕會顯示:「使用 Google 登入」

type

type: ProviderType;

參見 ProviderType


OAuth2Config<Profile>

待辦事項:撰寫文件

繼承自

類型參數

類型參數
Profile

屬性

[conformInternal]?

optional [conformInternal]: true;
請參閱

customFetch?

optional [customFetch]: (input, init?) => Promise<Response>;
請參閱
參數
參數類型
inputURL | RequestInfo
init?RequestInit
回傳值

Promise<Response>

account?

optional account: AccountCallback;

接收 OAuth 供應商回傳的完整 TokenSet,並回傳子集。它用於在資料庫中建立與使用者關聯的帳戶。

您需要調整資料庫的 帳戶模型 以符合回傳的屬性。請查閱您的 資料庫配接器 的文件以取得更多資訊。

預設值:access_tokenid_tokenrefresh_tokenexpires_atscopetoken_typesession_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
    }
  }
})
請參閱

allowDangerousEmailAccountLinking?

optional allowDangerousEmailAccountLinking: boolean;

通常,當您使用 OAuth 供應商登入,且另一個具有相同電子郵件地址的帳戶已存在時,帳戶不會自動連結。

在登入時自動連結帳戶在任意供應商之間是不安全的,因此預設為停用。請在我們的 安全性常見問題 中了解更多資訊。

但是,如果您信任所涉及的供應商已安全驗證與帳戶關聯的電子郵件地址,則允許自動帳戶連結可能是合乎需求的。設定 allowDangerousEmailAccountLinking: true 以啟用自動帳戶連結。

authorization?

optional authorization: string | AuthorizationEndpointHandler;

將使用者導向此 URL 以啟動登入流程。

授權端點

checks?

optional checks: ("none" | "state" | "pkce")[];

在回呼端點執行的 CSRF 保護。

預設值
["pkce"]
注意

當設定 redirectProxyUrlAuthConfig.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
覆寫

CommonProviderOptions.id

issuer?

optional issuer: string;
覆寫

PartialIssuer.issuer

jwks_endpoint

jwks_endpoint: any;
繼承自

PartialIssuer.jwks_endpoint

name

name: string;

供應商的名稱。顯示在預設登入頁面上。

覆寫

CommonProviderOptions.name

options?

optional options: OAuthUserConfig<Profile>;

profile?

optional profile: ProfileCallback<Profile>;

接收 OAuth 供應商回傳的完整 Profile,並回傳子集。它用於在資料庫中建立使用者。

預設值:idemailnameimage

請參閱

資料庫配接器:使用者模型

redirectProxyUrl?

optional redirectProxyUrl: string;

style?

optional style: OAuthProviderButtonStyles;

token?

optional token: string | TokenEndpointHandler;

type

type: "oauth";

參見 ProviderType

覆寫

CommonProviderOptions.type

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;
optional logo: string;

text?

optional text: string;
已棄用

OIDCConfig<Profile>

OAuth2Config 的延伸。

請參閱

https://openid.net/specs/openid-connect-core-1_0.html

繼承自

類型參數

類型參數
Profile

屬性

[conformInternal]?

optional [conformInternal]: true;
請參閱
繼承自

Omit.[conformInternal]

customFetch?

optional [customFetch]: (input, init?) => Promise<Response>;
請參閱
參數
參數類型
inputURL | RequestInfo
init?RequestInit
回傳值

Promise<Response>

繼承自

Omit.[customFetch]

account?

optional account: AccountCallback;

接收 OAuth 供應商回傳的完整 TokenSet,並回傳子集。它用於在資料庫中建立與使用者關聯的帳戶。

您需要調整資料庫的 帳戶模型 以符合回傳的屬性。請查閱您的 資料庫配接器 的文件以取得更多資訊。

預設值:access_tokenid_tokenrefresh_tokenexpires_atscopetoken_typesession_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
    }
  }
})
請參閱
繼承自

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,並回傳子集。它用於在資料庫中建立使用者。

預設值:idemailnameimage

參閱

資料庫配接器:使用者模型

繼承自

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;

參數

參數類型
tokensTokenSet

返回

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

參數

參數類型
profileProfile
tokensTokenSet

返回

Awaitable<User>


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 擴展自 Profileany

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>;
Auth.js © Balázs Orbán 和團隊 -2024