GoogleAuthProvider class

ProviderIdOAuthCredentialを生成するプロバイダー。グーグル。

サイン:

export declare class GoogleAuthProvider extends BaseOAuthProvider 

拡張: BaseOAuthProvider

コンストラクター

コンストラクタ修飾子説明
(コンストラクタ)() GoogleAuthProviderクラスの新しいインスタンスを構築します

プロパティ

財産修飾子タイプ説明
GOOGLE_SIGN_IN_METHOD static 'Google COM'常にSignInMethodに設定します。グーグル。
プロバイダーID static 'Google COM'常にProviderIdに設定します。グーグル。

メソッド

方法修飾子説明
資格情報(idToken, accessToken) static Google の認証情報を作成します。 IDトークンとアクセストークンの少なくとも一方が必要です。
credentialFromError(エラー) staticサインイン、リンク、または再認証操作中にスローされたAuthErrorから基になるOAuthCredentialを抽出するために使用されます。
credentialFromResult(userCredential) static UserCredentialから基礎となるOAuthCredentialを抽出するために使用されます

GoogleAuthProvider.(コンストラクター)

GoogleAuthProviderクラスの新しいインスタンスを構築します

サイン:

constructor();

GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD

常にSignInMethodに設定します。グーグル。

サイン:

static readonly GOOGLE_SIGN_IN_METHOD: 'google.com';

GoogleAuthProvider.PROVIDER_ID

常にProviderIdに設定します。グーグル。

サイン:

static readonly PROVIDER_ID: 'google.com';

GoogleAuthProvider.credential()

Google の認証情報を作成します。 IDトークンとアクセストークンの少なくとも一方が必要です。

サイン:

static credential(idToken?: string | null, accessToken?: string | null): OAuthCredential;

パラメーター

パラメータタイプ説明
idトークン文字列 |ヌルGoogle ID トークン。
アクセストークン文字列 |ヌルGoogleのアクセストークン。

戻り値:

OAuth認証情報

// \`googleUser\` from the onsuccess Google Sign In callback.
const credential = GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
const result = await signInWithCredential(credential);

GoogleAuthProvider.credentialFromError()

サインイン、リンク、または再認証操作中にスローされたAuthErrorから基になるOAuthCredentialを抽出するために使用されます。

サイン:

static credentialFromError(error: FirebaseError): OAuthCredential | null;

パラメーター

パラメータタイプ説明
エラーFirebaseError

戻り値:

OAuth認証情報|ヌル

GoogleAuthProvider.credentialFromResult()

UserCredentialから基礎となるOAuthCredentialを抽出するために使用されます

サイン:

static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;

パラメーター

パラメータタイプ説明
ユーザー資格情報ユーザー資格情報ユーザーの資格情報。

戻り値:

OAuth認証情報|ヌル

例1

// Sign in using a redirect.
const provider = new GoogleAuthProvider();
// Start a sign in process for an unauthenticated user.
provider.addScope('profile');
provider.addScope('email');
await signInWithRedirect(auth, provider);
// This will trigger a full page redirect away from your app

// After returning from the redirect when your app initializes you can obtain the result
const result = await getRedirectResult(auth);
if (result) {
  // This is the signed-in user
  const user = result.user;
  // This gives you a Google Access Token.
  const credential = GoogleAuthProvider.credentialFromResult(result);
  const token = credential.accessToken;
}

例 2

// Sign in using a popup.
const provider = new GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
const result = await signInWithPopup(auth, provider);

// The signed-in user info.
const user = result.user;
// This gives you a Google Access Token.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;