popup_closed_by_user error when trying to test google oauth in my web application

南笙酒味 提交于 2019-12-11 00:58:56

问题


So i am trying to implement google login into my web application using angularJS. The popup opens up to login into my google account or to select one the existing accounts but after login the popup closes with an error in the console (popup_closed_by_user)

The problem is consistant 100% of the times i tried. I have tried it on chrome and edge, same result. clearing cookies and cache doesnt help. google + API and oauth is enabled. The origin url is added correctly. The code is in angularJS.

.directive('googleSignInButton',function(){
  return {
      scope:{
          gClientId:'@',
          callback: '&onSignIn'
      },
      template: '<button class="button button-block button-positive" ng-click="onSignInButtonClick()">Sign in with Google</button>',
      controller: ['$scope','$attrs',function($scope, $attrs){
          gapi.load('auth2', function() {
            //load in the auth2 api's, without it gapi.auth2 will be undefined
              gapi.auth2.init(
                      {
                          client_id: $attrs.gClientId
                      }
              );
              var GoogleAuth  = gapi.auth2.getAuthInstance();//get's a GoogleAuth instance with your client-id, needs to be called after gapi.auth2.init
              $scope.onSignInButtonClick=function(){//add a function to the controller so ng-click can bind to it
                  GoogleAuth.signIn().then(function(response){//request to sign in
                      $scope.callback({response:response});
                  });
              };
          });
      }]
  };
});

回答1:


adding gapi.auth2.SignInOptions e.g { prompt : 'consent' } to signIn function will force the popup to open.



来源:https://stackoverflow.com/questions/55456326/popup-closed-by-user-error-when-trying-to-test-google-oauth-in-my-web-applicatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!