OAuthProvider class

汎用OAuthCredentialを生成するプロバイダー

サイン:

export declare class OAuthProvider extends BaseOAuthProvider 

拡張: BaseOAuthProvider

メソッド

方法修飾子説明
資格情報(パラメータ)汎用 OAuth プロバイダーのアクセス トークンまたは ID トークンからOAuthCredentialを作成します。
credentialFromError(エラー) staticサインイン、リンク、または再認証操作中にスローされたAuthErrorから基になるOAuthCredentialを抽出するために使用されます。
credentialFromJSON(json) static JSON 文字列またはプレーン オブジェクトからOAuthCredentialを作成します。
credentialFromResult(userCredential) static UserCredentialから基礎となるOAuthCredentialを抽出するために使用されます

OAuthProvider.credential()

汎用 OAuth プロバイダーのアクセス トークンまたは ID トークンからOAuthCredentialを作成します。

nonce フィールドを持つ ID トークンが提供される場合は、生の nonce が必要です。生の nonce の SHA-256 ハッシュは、ID トークンの nonce フィールドと一致する必要があります。

サイン:

credential(params: OAuthCredentialOptions): OAuthCredential;

パラメーター

パラメータタイプ説明
パラメータOAuthCredentialオプションID トークン、アクセス トークン、生のノンスを含むオプション オブジェクト、または ID トークン文字列のいずれか。

戻り値:

OAuth認証情報

// `googleUser` from the onsuccess Google Sign In callback.
// Initialize a generate OAuth provider with a `google.com` providerId.
const provider = new OAuthProvider('google.com');
const credential = provider.credential({
  idToken: googleUser.getAuthResponse().id_token,
});
const result = await signInWithCredential(credential);

OAuthProvider.credentialFromError()

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

サイン:

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

パラメーター

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

戻り値:

OAuth認証情報|ヌル

OAuthProvider.credentialFromJSON()

JSON 文字列またはプレーン オブジェクトからOAuthCredentialを作成します。

サイン:

static credentialFromJSON(json: object | string): OAuthCredential;

パラメーター

パラメータタイプ説明
jsonオブジェクト |弦プレーンオブジェクトまたはJSON文字列

戻り値:

OAuth認証情報

OAuthProvider.credentialFromResult()

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

サイン:

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

パラメーター

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

戻り値:

OAuth認証情報|ヌル

例1

// Sign in using a redirect.
const provider = new OAuthProvider('google.com');
// 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 OAuth Access Token for the provider.
  const credential = provider.credentialFromResult(auth, result);
  const token = credential.accessToken;
}

例 2

// Sign in using a popup.
const provider = new OAuthProvider('google.com');
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 OAuth Access Token for the provider.
const credential = provider.credentialFromResult(auth, result);
const token = credential.accessToken;