I'm trying to integrate google sign in my website, and i'm using firebase for authentication and later I do authorization the user for access their google drives.
and after getting access of their Google drives
i want the page to redirect to another page.(localhost:8080/afterlogin)
, where it will be displayed "WELCOME"
however the user doesn't get to the desired page, I've added the exact redierct_uri in the developer console but no help.
here is my code for initializing the auth object.
gapi.load('auth2', function () {
// Retrieve the singleton for the GoogleAuth library and set up the client.
auth2 = gapi.auth2.init({
client_id: 'MYID.apps.googleusercontent',
cookiepolicy: 'single_host_origin',
redirect_uri: 'http://localhost:8080/afterlogin'
// Request scopes in addition to 'profile' and 'email'
//scope: 'additional_scope'
});
i'm using javascript and i read in the docs that javascript api does not use redirect_uris.
However in the docs here
it is stated that we can add redirect_uris in by using gapi.auth2.ClientConfig
instead of gapi.auth2.init
.
but however, using gapi.auth2.ClientConfig
instead of gapi.auth2.init
gives me and error. so i added redirect_uri
in the latter one as seen in the code above. maybe that is why it is not working?
or i'm doing something wrong in using gapi.auth2.ClientConfig
?
any guesses?
I'm trying to integrate google sign in my website, and i'm using firebase for authentication and later I do authorization the user for access their google drives.
and after getting access of their Google drives
i want the page to redirect to another page.(localhost:8080/afterlogin)
, where it will be displayed "WELCOME"
however the user doesn't get to the desired page, I've added the exact redierct_uri in the developer console but no help.
here is my code for initializing the auth object.
gapi.load('auth2', function () {
// Retrieve the singleton for the GoogleAuth library and set up the client.
auth2 = gapi.auth2.init({
client_id: 'MYID.apps.googleusercontent.',
cookiepolicy: 'single_host_origin',
redirect_uri: 'http://localhost:8080/afterlogin'
// Request scopes in addition to 'profile' and 'email'
//scope: 'additional_scope'
});
i'm using javascript and i read in the docs that javascript api does not use redirect_uris.
However in the docs here
it is stated that we can add redirect_uris in by using gapi.auth2.ClientConfig
instead of gapi.auth2.init
.
but however, using gapi.auth2.ClientConfig
instead of gapi.auth2.init
gives me and error. so i added redirect_uri
in the latter one as seen in the code above. maybe that is why it is not working?
or i'm doing something wrong in using gapi.auth2.ClientConfig
?
any guesses?
Share Improve this question asked Feb 9, 2018 at 14:27 P.hunterP.hunter 1,3652 gold badges23 silver badges46 bronze badges1 Answer
Reset to default 5The docs say that you need to override the default redirect_uri using ux_mode='redirect'. Sometimes Google's documentation is a lot more plicated than it needs to be. I presume you are handling the resulting promises from the code you posted. I would try this:
gapi.load('auth2', function () {
auth2 = gapi.auth2.init({
client_id: 'MYID.apps.googleusercontent.',
cookiepolicy: 'single_host_origin',
ux_mode: 'redirect',
redirect_uri: 'http://localhost:8080/afterlogin'
// Request scopes in addition to 'profile' and 'email'
//scope: 'additional_scope'
});
auth2.signIn().then(function() {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('Full Name: ' + profile.getName());
})
From the docs, under gapi.auth2.ClientConfig
edit - I fixed the issue with the =
sign