Method: accounts.signInWithPassword

使用電子郵件地址和密碼登入使用者。如果登入成功,系統會為已驗證的使用者核發新的 Identity Platform ID 權杖和重新整理權杖。

如要識別 Google Cloud 專案,請在要求中提供 API 金鑰

HTTP 要求

POST https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword

這個網址使用 gRPC 轉碼語法。

要求主體

要求主體包含下列結構的資料:

JSON 表示法
{
  "email": string,
  "password": string,
  "pendingIdToken": string,
  "captchaChallenge": string,
  "captchaResponse": string,
  "instanceId": string,
  "delegatedProjectNumber": string,
  "idToken": string,
  "returnSecureToken": boolean,
  "tenantId": string,
  "clientType": enum (ClientType),
  "recaptchaVersion": enum (RecaptchaVersion)
}
欄位
email

string

這是必要旗標,使用者用來登入的電子郵件地址。電子郵件長度不得超過 256 個半形字元,格式為 name@domain.tld。電子郵件也應符合 RFC 822 的 addr-spec 產生方式。

password

string

這是必要旗標,使用者提供的密碼,用於登入帳戶。

pendingIdToken
(deprecated)

string

captchaChallenge
(deprecated)

string

captchaResponse

string

reCAPTCHA 用戶端整合功能提供的 reCAPTCHA 權杖。reCAPTCHA Enterprise 會使用這項權杖進行風險評估。啟用 reCAPTCHA Enterprise 時必須提供。

instanceId
(deprecated)

string

delegatedProjectNumber
(deprecated)

string (int64 format)

idToken
(deprecated)

string

returnSecureToken

boolean

應一律為 true。

tenantId

string

使用者要登入的 Identity Platform 租用戶 ID。如果未設定,使用者會登入專案中的預設 Identity Platform 例項。

clientType

enum (ClientType)

用戶端類型 (網頁、Android 或 iOS)。啟用 reCAPTCHA Enterprise 時必須提供。

recaptchaVersion

enum (RecaptchaVersion)

captchaResponse 中 reCAPTCHA 權杖的 reCAPTCHA 版本。

回應主體

accounts.signInWithPassword 的回應訊息。

如果成功,回應主體會含有以下結構的資料:

JSON 表示法
{
  "kind": string,
  "localId": string,
  "email": string,
  "displayName": string,
  "idToken": string,
  "registered": boolean,
  "profilePicture": string,
  "oauthAccessToken": string,
  "oauthExpireIn": integer,
  "oauthAuthorizationCode": string,
  "refreshToken": string,
  "expiresIn": string,
  "mfaPendingCredential": string,
  "mfaInfo": [
    {
      object (MfaEnrollment)
    }
  ],
  "userNotifications": [
    {
      object (UserNotification)
    }
  ]
}
欄位
kind
(deprecated)

string

localId

string

已驗證使用者的 ID。回應中一律會出現。

email

string

已驗證使用者的電子郵件地址。回應中一律會出現。

displayName

string

儲存在帳戶屬性中的使用者顯示名稱。

idToken

string

經過驗證的使用者所需的 Identity Platform ID 權杖。

registered
(deprecated)

boolean

電子郵件地址是否屬於現有帳戶。一律為 true。

profilePicture

string

儲存在帳戶屬性中的使用者個人資料相片。

oauthAccessToken
(deprecated)

string

OAuth2 存取權杖。

oauthExpireIn
(deprecated)

integer

存取權杖的過期時間 (以秒為單位)。

oauthAuthorizationCode
(deprecated)

string

refreshToken

string

已驗證使用者的 Identity Platform 重新整理權杖。

expiresIn

string (int64 format)

Identity Platform ID 權杖到期前的秒數。

mfaPendingCredential

string

這項隱含的字串可做為證明使用者已成功通過第一層驗證的證明。

mfaInfo[]

object (MfaEnrollment)

帳戶啟用的多重驗證供應商資訊。如果使用者需要使用多重驗證功能完成登入程序,就會顯示這項屬性。

userNotifications[]

object (UserNotification)

使用者警告通知。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/identitytoolkit
  • https://www.googleapis.com/auth/cloud-platform

詳情請參閱 Authentication Overview

UserNotification

使用者警告通知。

JSON 表示法
{
  "notificationCode": enum (NotificationCode),
  "notificationMessage": string
}
欄位
notificationCode

enum (NotificationCode)

警告通知列舉。可用於本地化。

notificationMessage

string

警告通知字串。可用做備用值。

NotificationCode

警告通知列舉。可用於本地化。

列舉
NOTIFICATION_CODE_UNSPECIFIED 未指定通知。
MISSING_LOWERCASE_CHARACTER 密碼缺少小寫字元。
MISSING_UPPERCASE_CHARACTER 密碼缺少大寫字元。
MISSING_NUMERIC_CHARACTER 密碼缺少數字。
MISSING_NON_ALPHANUMERIC_CHARACTER 密碼缺少非英數字元。
MINIMUM_PASSWORD_LENGTH 密碼長度未達規定長度下限。
MAXIMUM_PASSWORD_LENGTH 密碼長度超過規定上限。