// Using a redirect.
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// This gives you a Google Access Token.var token = result.credential.accessToken;
}
var user = result.user;
});
// Start a sign in process for an unauthenticated user.var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);
example
// Using a popup.var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token.var token = result.credential.accessToken;
// The signed-in user info.var user = result.user;
});
Sets the OAuth custom parameters to pass in a Google OAuth request for popup
and redirect sign-in operations.
Valid parameters include 'hd', 'hl', 'include_granted_scopes', 'login_hint'
and 'prompt'.
For a detailed list, check the
Google
documentation.
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.
Creates a credential for Google. At least one of ID token and access token
is required.
example
// \`googleUser\` from the onsuccess Google Sign In callback.var credential = firebase.auth.GoogleAuthProvider.credential(
googleUser.getAuthResponse().id_token);
firebase.auth().signInWithCredential(credential)
[[["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,["- [firebase](/docs/reference/js/v8/firebase).\n- [auth](/docs/reference/js/v8/firebase.auth).\n- GoogleAuthProvider \nGoogle auth provider.\n\nexample\n:\n\n // Using a redirect.\n firebase.auth().getRedirectResult().then(function(result) {\n if (result.credential) {\n // This gives you a Google Access Token.\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.GoogleAuthProvider();\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.GoogleAuthProvider();\n provider.addScope('profile');\n provider.addScope('email');\n firebase.auth().signInWithPopup(provider).then(function(result) {\n // This gives you a Google Access Token.\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/js/v8/firebase.auth.Auth#onauthstatechanged) to receive sign in state\n changes.\n\nImplements\n\n- [AuthProvider](/docs/reference/js/v8/firebase.auth.AuthProvider)\n\nIndex\n\nProperties\n\n- [providerId](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#providerid)\n- [GOOGLE_SIGN_IN_METHOD](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#google_sign_in_method)\n- [PROVIDER_ID](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#provider_id)\n\nMethods\n\n- [addScope](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#addscope)\n- [setCustomParameters](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#setcustomparameters)\n- [credential](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#credential)\n\nProperties\n\nproviderId \nproviderId: string\n| Implementation of [AuthProvider](/docs/reference/js/v8/firebase.auth.AuthProvider).[providerId](/docs/reference/js/v8/firebase.auth.AuthProvider#providerid)\n| Inherited from [GoogleAuthProvider](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider).[providerId](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#providerid)\n\nStatic GOOGLE_SIGN_IN_METHOD \nGOOGLE_SIGN_IN_METHOD: string \nThis corresponds to the sign-in method identifier as returned in\n[firebase.auth.Auth.fetchSignInMethodsForEmail](/docs/reference/js/v8/firebase.auth.Auth#fetchsigninmethodsforemail).\n\nStatic PROVIDER_ID \nPROVIDER_ID: string\n\nMethods\n\naddScope\n\n- addScope ( scope : string ) : [AuthProvider](/docs/reference/js/v8/firebase.auth.AuthProvider)\n-\n Inherited from [GoogleAuthProvider](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider).[addScope](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#addscope) \n\n Parameters\n -\n\n scope: string \n Google OAuth scope.\n\n Returns [AuthProvider](/docs/reference/js/v8/firebase.auth.AuthProvider)\n\n The provider instance itself.\n\nsetCustomParameters\n\n- setCustomParameters ( customOAuthParameters : Object ) : [AuthProvider](/docs/reference/js/v8/firebase.auth.AuthProvider)\n-\n Inherited from [GoogleAuthProvider](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider).[setCustomParameters](/docs/reference/js/v8/firebase.auth.GoogleAuthProvider#setcustomparameters) \n Sets the OAuth custom parameters to pass in a Google OAuth request for popup\n and redirect sign-in operations.\n Valid parameters include 'hd', 'hl', 'include_granted_scopes', 'login_hint'\n and 'prompt'.\n For a detailed list, check the\n [Google](https://goo.gl/Xo01Jm)\n documentation.\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 customOAuthParameters: Object \n The custom OAuth parameters to pass\n in the OAuth request.\n\n Returns [AuthProvider](/docs/reference/js/v8/firebase.auth.AuthProvider)\n\n The provider instance itself.\n\nStatic credential\n\n- credential ( idToken ? : string \\| null , accessToken ? : string \\| null ) : [OAuthCredential](/docs/reference/js/v8/firebase.auth.OAuthCredential)\n- Creates a credential for Google. At least one of ID token and access token\n is required.\n\n example\n :\n\n // \\`googleUser\\` from the onsuccess Google Sign In callback.\n var credential = firebase.auth.GoogleAuthProvider.credential(\n googleUser.getAuthResponse().id_token);\n firebase.auth().signInWithCredential(credential)\n\n\n Parameters\n -\n\n Optional idToken: string \\| null \n Google ID token.\n -\n\n Optional accessToken: string \\| null \n Google access token.\n\n Returns [OAuthCredential](/docs/reference/js/v8/firebase.auth.OAuthCredential)\n\nThe auth provider credential."]]
Google auth provider.
// Using a redirect. firebase.auth().getRedirectResult().then(function(result) { if (result.credential) { // This gives you a Google Access Token. var token = result.credential.accessToken; } var user = result.user; }); // Start a sign in process for an unauthenticated user. var provider = new firebase.auth.GoogleAuthProvider(); provider.addScope('profile'); provider.addScope('email'); firebase.auth().signInWithRedirect(provider);
// Using a popup. var provider = new firebase.auth.GoogleAuthProvider(); provider.addScope('profile'); provider.addScope('email'); firebase.auth().signInWithPopup(provider).then(function(result) { // This gives you a Google Access Token. var token = result.credential.accessToken; // The signed-in user info. var user = result.user; });
firebase.auth.Auth.onAuthStateChanged to receive sign in state changes.