The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/auth > OAuthProvider

OAuthProvider class

Provider for generating generic OAuthCredential.

Signature:

export declare class OAuthProvider extends BaseOAuthProvider 

Extends: BaseOAuthProvider

Example 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;
}

Example 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;

Methods

Method Modifiers Description
credential(params) Creates a OAuthCredential from a generic OAuth provider's access token or ID token.
credentialFromError(error) static Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation.
credentialFromJSON(json) static Creates an OAuthCredential from a JSON string or a plain object.
credentialFromResult(userCredential) static Used to extract the underlying OAuthCredential from a UserCredential.