GoogleAuthProvider class

ProviderId 에 대한 OAuthCredential을 생성하는 공급자 .GOOGLE.

서명:

export declare class GoogleAuthProvider extends BaseOAuthProvider 

확장: BaseOAuthProvider

생성자

건설자 수정자 설명
(건설자)() GoogleAuthProvider 클래스의 새 인스턴스를 생성합니다.

속성

재산 수정자 유형 설명
GOOGLE_SIGN_IN_METHOD static 'google.com' 항상 SignInMethod 로 설정 .GOOGLE.
PROVIDER_ID static 'google.com' 항상 ProviderId 로 설정 .GOOGLE.

행동 양식

방법 수정자 설명
자격 증명(idToken, accessToken) static Google에 대한 사용자 인증 정보를 만듭니다. ID 토큰과 액세스 토큰 중 하나 이상이 필요합니다.
자격 증명FromError(오류) static 로그인, 링크 또는 재인증 작업 중에 발생한 AuthError 에서 기본 OAuthCredential을 추출하는 데 사용됩니다.
credentialFromResult(userCredential) static UserCredential 에서 기본 OAuthCredential을 추출하는 데 사용됩니다. .

GoogleAuthProvider.(생성자)

GoogleAuthProvider 클래스의 새 인스턴스를 생성합니다.

서명:

constructor();

GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD

항상 SignInMethod 로 설정 .GOOGLE.

서명:

static readonly GOOGLE_SIGN_IN_METHOD: 'google.com';

GoogleAuthProvider.PROVIDER_ID

항상 ProviderId 로 설정 .GOOGLE.

서명:

static readonly PROVIDER_ID: 'google.com';

GoogleAuthProvider.credential()

Google에 대한 사용자 인증 정보를 만듭니다. ID 토큰과 액세스 토큰 중 하나 이상이 필요합니다.

서명:

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

매개변수

매개변수 유형 설명
아이디토큰 문자열 | 없는 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;

매개변수

매개변수 유형 설명
오류 Firebase오류

보고:

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;