-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle-auth.js
More file actions
52 lines (45 loc) · 1.25 KB
/
Copy pathgoogle-auth.js
File metadata and controls
52 lines (45 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
angular.module('google.auth', [
'google.platform'
]).provider('GoogleAuth', function (
) {
var provider = {
params: {},
$get: function (
$q,
$rootScope,
GooglePlatform
) {
var signIn = $q.defer();
function signInByGoogle (params) {
GooglePlatform.promise.then(function (google) {
google.auth.signIn(angular.extend({
callback: googleSignInCallback
}, provider.params, params));
return google;
});
return signIn.promise;
}
function googleSignInCallback (response) {
if (response.status.signed_in) {
$rootScope.$broadcast('google.auth:signInSuccess', response);
signIn.resolve(response);
} else if (response.error.user_signed_out) {
$rootScope.$broadcast('google.auth:signOutSuccess', response);
} else {
$rootScope.$broadcast('google.auth:signInError', response);
signIn.reject(response);
}
}
return {
signIn: signInByGoogle,
signOut: function () {
GooglePlatform.promise.then(function (google) {
google.auth.signOut();
return google;
});
}
};
}
};
return provider;
});