// Using a redirect.
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// This gives you the OAuth Access Token for that provider.var token = result.credential.accessToken;
}
var user = result.user;
});
// Start a sign in process for an unauthenticated user.var provider = new firebase.auth.OAuthProvider('google.com');
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);
example
// Using a popup.var provider = new firebase.auth.OAuthProvider('google.com');
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you the OAuth Access Token for that provider.var token = result.credential.accessToken;
// The signed-in user info.var user = result.user;
});
Creates a Firebase credential from a generic OAuth provider's access token or
ID token. The raw nonce is required when an ID token with a nonce field is
provided. The SHA-256 hash of the raw nonce must match the nonce field in
the ID token.
example
// `googleUser` from the onsuccess Google Sign In callback.// Initialize a generate OAuth provider with a `google.com` providerId.var provider = new firebase.auth.OAuthProvider('google.com');
var credential = provider.credential({
idToken: googleUser.getAuthResponse().id_token,
});
firebase.auth().signInWithCredential(credential)
Sets the OAuth custom parameters to pass in an OAuth request for popup
and redirect sign-in operations.
For a detailed list, check the
reserved required OAuth 2.0 parameters such as client_id, redirect_uri,
scope, response_type and state are not allowed and will be ignored.
Parameters
customOAuthParameters: Object
The custom OAuth parameters to pass
in the OAuth request.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-07-27 UTC."],[],[],null,["# OAuthProvider | JavaScript SDK\n\n- [firebase](/docs/reference/node/firebase).\n- [auth](/docs/reference/node/firebase.auth).\n- OAuthProvider\n==========================================================================================================\n\nGeneric OAuth provider.\n\nexample\n:\n\n // Using a redirect.\n firebase.auth().getRedirectResult().then(function(result) {\n if (result.credential) {\n // This gives you the OAuth Access Token for that provider.\n var token = result.credential.accessToken;\n }\n var user = result.user;\n });\n\n // Start a sign in process for an unauthenticated user.\n var provider = new firebase.auth.OAuthProvider('google.com');\n provider.addScope('profile');\n provider.addScope('email');\n firebase.auth().signInWithRedirect(provider);\n\n\nexample\n:\n\n // Using a popup.\n var provider = new firebase.auth.OAuthProvider('google.com');\n provider.addScope('profile');\n provider.addScope('email');\n firebase.auth().signInWithPopup(provider).then(function(result) {\n // This gives you the OAuth Access Token for that provider.\n var token = result.credential.accessToken;\n // The signed-in user info.\n var user = result.user;\n });\n\n\nsee\n\n: [firebase.auth.Auth.onAuthStateChanged](/docs/reference/node/firebase.auth.Auth#onauthstatechanged) to receive sign in state\n changes.\n\nparam\n\n: The associated provider ID, such as `github.com`.\n\n### Implements\n\n- [AuthProvider](/docs/reference/node/firebase.auth.AuthProvider)\n\nIndex\n-----\n\n### Constructors\n\n- [constructor](/docs/reference/node/firebase.auth.OAuthProvider#constructor)\n\n### Properties\n\n- [providerId](/docs/reference/node/firebase.auth.OAuthProvider#providerid)\n\n### Methods\n\n- [addScope](/docs/reference/node/firebase.auth.OAuthProvider#addscope)\n- [credential](/docs/reference/node/firebase.auth.OAuthProvider#credential)\n- [setCustomParameters](/docs/reference/node/firebase.auth.OAuthProvider#setcustomparameters)\n\nConstructors\n------------\n\n### constructor\n\n- new OAuthProvider ( providerId : string ) : [OAuthProvider](/docs/reference/node/firebase.auth.OAuthProvider)\n-\n\n #### Parameters\n\n -\n\n ##### providerId: string\n\n #### Returns [OAuthProvider](/docs/reference/node/firebase.auth.OAuthProvider)\n\nProperties\n----------\n\n### providerId\n\nproviderId: string\n| Implementation of [AuthProvider](/docs/reference/node/firebase.auth.AuthProvider).[providerId](/docs/reference/node/firebase.auth.AuthProvider#providerid)\n\nMethods\n-------\n\n### addScope\n\n- addScope ( scope : string ) : [AuthProvider](/docs/reference/node/firebase.auth.AuthProvider)\n-\n\n #### Parameters\n\n -\n\n ##### scope: string\n\n Provider OAuth scope to add.\n\n #### Returns [AuthProvider](/docs/reference/node/firebase.auth.AuthProvider)\n\n### credential\n\n- credential ( optionsOrIdToken : [OAuthCredentialOptions](/docs/reference/node/firebase.auth.OAuthCredentialOptions) \\| string \\| null , accessToken ? : string ) : [OAuthCredential](/docs/reference/node/firebase.auth.OAuthCredential)\n- Creates a Firebase credential from a generic OAuth provider's access token or\n ID token. The raw nonce is required when an ID token with a nonce field is\n provided. The SHA-256 hash of the raw nonce must match the nonce field in\n the ID token.\n\n example\n :\n\n // `googleUser` from the onsuccess Google Sign In callback.\n // Initialize a generate OAuth provider with a `google.com` providerId.\n var provider = new firebase.auth.OAuthProvider('google.com');\n var credential = provider.credential({\n idToken: googleUser.getAuthResponse().id_token,\n });\n firebase.auth().signInWithCredential(credential)\n\n\n #### Parameters\n\n -\n\n ##### optionsOrIdToken: [OAuthCredentialOptions](/docs/reference/node/firebase.auth.OAuthCredentialOptions) \\| string \\| null\n\n Either the options object containing\n the ID token, access token and raw nonce or the ID token string.\n -\n\n ##### Optional accessToken: string\n\n The OAuth access token.\n\n #### Returns [OAuthCredential](/docs/reference/node/firebase.auth.OAuthCredential)\n\n### setCustomParameters\n\n- setCustomParameters ( customOAuthParameters : Object ) : [AuthProvider](/docs/reference/node/firebase.auth.AuthProvider)\n- Sets the OAuth custom parameters to pass in an OAuth request for popup\n and redirect sign-in operations.\n For a detailed list, check the\n reserved required OAuth 2.0 parameters such as `client_id`, `redirect_uri`,\n `scope`, `response_type` and `state` are not allowed and will be ignored.\n\n #### Parameters\n\n -\n\n ##### customOAuthParameters: Object\n\n The custom OAuth parameters to pass\n in the OAuth request.\n\n #### Returns [AuthProvider](/docs/reference/node/firebase.auth.AuthProvider)"]]
Generic OAuth provider.
// Using a redirect. firebase.auth().getRedirectResult().then(function(result) { if (result.credential) { // This gives you the OAuth Access Token for that provider. var token = result.credential.accessToken; } var user = result.user; }); // Start a sign in process for an unauthenticated user. var provider = new firebase.auth.OAuthProvider('google.com'); provider.addScope('profile'); provider.addScope('email'); firebase.auth().signInWithRedirect(provider);
// Using a popup. var provider = new firebase.auth.OAuthProvider('google.com'); provider.addScope('profile'); provider.addScope('email'); firebase.auth().signInWithPopup(provider).then(function(result) { // This gives you the OAuth Access Token for that provider. var token = result.credential.accessToken; // The signed-in user info. var user = result.user; });
firebase.auth.Auth.onAuthStateChanged to receive sign in state changes.
The associated provider ID, such as
github.com
.