lundi 5 avril 2021

How to run development http server on localhost authenticating with Google OAuth 2 after App is in production?

I have developed a javascript web application that uses OAuth 2 in order to authenticate Google users. While the app was in test stage, I could login users both in my local http-server development environment (localhost) and in the production environment (web server with proper domain name).

However, since I have upgraded my web application to production, I cannot login at localhost anymore. The code below used to work, but now auth2.isSignedIn is always false when running in localhost, even after a successful login.

  const signinChanged = function (val) {
    // do something with the credentials of the logged in user
  } 

  auth2 = gapi.auth2.init({
    client_id: 'CLIENT_ID.apps.googleusercontent.com'
  }).then( function () {
    auth2 = gapi.auth2.getAuthInstance()
    auth2.isSignedIn.listen(signinChanged);
  });
})

What is the proper way to deal with development vs. production environments when you are using OAuth2?




Aucun commentaire:

Enregistrer un commentaire