尝试在我的Web应用程序中测试google oauth时出现popup_closed_by_user错误 [英] popup_closed_by_user error when trying to test google oauth in my web application

查看:402
本文介绍了尝试在我的Web应用程序中测试google oauth时出现popup_closed_by_user错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试使用angularJS在我的Web应用程序中实现google登录.弹出窗口打开以登录我的Google帐户或选择一个现有帐户,但登录后弹出窗口关闭,控制台中出现错误(popup_closed_by_user)

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)

问题是我尝试过的100%一致.我已经在chrome和edge上尝试过,同样的结果.清除Cookie和缓存无济于事. google + API和oauth已启用.原始网址已正确添加. 该代码在angularJS中.

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});
                  });
              };
          });
      }]
  };
});

推荐答案

添加

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

这篇关于尝试在我的Web应用程序中测试google oauth时出现popup_closed_by_user错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆