问题
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