I am using OAuth2.0 in google drive api authentication. I have an isSignedIn
listener that has afterSignIn
as a callback.
My problem: after signing in, afterSignIn()
function is not fired. Does someone know how to fix this?
function googleDriveAuthentication($rootScope){
var API_KEY = '...'
var CLIENT_ID = '...';
var SCOPES = 'https://www.googleapis.com/auth/drive';
this.authenticate = function(){
gapi.load('client:auth2',authorize);
}
function authorize(){
gapi.client.setApiKey(API_KEY);
gapi.auth2.init({
client_id: CLIENT_ID,
scope: SCOPES
}).then(function(authResult){
var auth2 = gapi.auth2.getAuthInstance();
auth2.isSignedIn.listen(afterSignIn);
auth2.signIn();
});
}
function afterSignIn(){
console.log('authenticated successfully');
$rootScope.authenticated = true;
$rootScope.$broadcast('authenticated');
gapi.client.load('drive', 'v3');
}
}