Zee
Zee

Reputation: 151

google Oauth2.0 authenticate - not continue to redirect_uri

I'm trying to implement login with google to my web site. The users can visit my site in 3 domains

1) regular link (HTTP and WWW...) 2) http://example.com - no www 3) apps.facebook.com/example - facebook app

We want to allow the user connect google in those three options.

We're using gapi (google javascript library) in order to authenticate the user. My code looks like:

   var config = {
        'client_id': 'my_client_id',
        'scope': 'my_scopes',
        **'redirect_uri' : "https://www.example.com/oauth/",**
        'immediate': immediate
    };
    **gapi.auth.authorize(config, function(){});**

As you can see I'm setting my redirect uri as part of the config of gapi. We've created some popup in order to give the same uri for the three domains.

My problem is that in case I'm login to my site from the domain without the WWW, the authorize isn't working and the user isn't redirect to the redirect_uri link - which means, we don't have his token.

In case I'm removing the WWW in the redirect_uri (so it will looks like https://example.com/oauth/) the facebook domain isn't working...

It's so frustrated.. Is anyone familiar with this kind of problem? Any idea?

We've spent on it too many hours....

Thanks Z

Upvotes: 1

Views: 1406

Answers (1)

Hans Z.
Hans Z.

Reputation: 53928

You can register multiple redirect URIs for a single client in the Google API Console so you would register one for each domain and pass the one for the currently accessed domain in the redirect_uri parameter of the authorization request. You don't need to use the same redirect URI across your domains so that should solve your state/token restoration problems. enter image description here

Upvotes: 1

Related Questions