GoogleWebComponents / google-signin

Google Sign-in web component
https://elements.polymer-project.org/elements/google-signin
Other
279 stars 89 forks source link

ux_mode not an option parameter for gapi.auth2.init #162

Open monisha3107 opened 6 years ago

monisha3107 commented 6 years ago

I am trying to avoid a browser pop-up and use ux_mode='redirect' during init() or signIn() and it seems like I cannot use this as one of the option parameters to either of those methods. Has this been removed/modified?

index.html has this and loads appcomponent.html: <script src="https://apis.google.com/js/platform.js" async defer></script>

appcomponent.html has this:

<google-signin id="signin"
               style="display: inline-block;"
               [clientId]="clientId"
               [scope]="scope"
               (googleSignInSuccess)="onGoogleSignIn()">
</google-signin>

<button style="float:right; height: 36px; display: inline-block;" class="btn btn-default" (click)="onGoogleSignOut();">Sign out</button>

And appcomponent.ts has the following:

 onGoogleSignIn() {

    let googleAuth = gapi.auth2.getAuthInstance();
    this.user = googleAuth.currentUser.get();

    if (googleAuth.currentUser.get().isSignedIn()) {
      googleAuth.signIn().then((data) => {
        this.token = data.Zi.access_token;
      });
    }
    else
    {
      let authResp = this.user.getAuthResponse();
      this.token = authResp.access_token;
    }
  }

  onGoogleSignOut() {
    gapi.auth2.getAuthInstance().signOut().then(function () {
      console.log('User signed out.');
    });
  }

This works just fine. But I wanted to not have the pop-up and instead have the user be redirected to another page to select the google account to login with. So, I was trying to specify _uxmode in the signIn() parameters or add in a onLoad() function with init().

dman777 commented 5 years ago

I get the pop-up using Polymer 1 with:

    <google-signin
          on-google-signin-success="googleSignInSuccess"
          client-id="333-foo.apps.googleusercontent.com"
          label-signin="Login with Google"
        ></google-signin>