forked from zquestz/omniauth-google-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
43 lines (42 loc) · 1.2 KB
/
auth.js
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
// Basic hybrid auth example following the pattern at:
// https://developers.google.com/api-client-library/javascript/features/authentication#Authexample
jQuery(function() {
return $.ajax({
url: 'https://apis.google.com/js/client:plus.js?onload=gpAsyncInit',
dataType: 'script',
cache: true
});
});
window.gpAsyncInit = function() {
gapi.auth.authorize({
immediate: true,
response_type: 'code',
cookie_policy: 'single_host_origin',
client_id: 'YOUR_CLIENT_ID',
scope: 'email profile'
}, function(response) {
return;
});
$('.googleplus-login').click(function(e) {
e.preventDefault();
gapi.auth.authorize({
immediate: false,
response_type: 'code',
cookie_policy: 'single_host_origin',
client_id: 'YOUR_CLIENT_ID',
scope: 'email profile'
}, function(response) {
if (response && !response.error) {
// google authentication succeed, now post data to server.
jQuery.ajax({type: 'POST', url: "/auth/google_oauth2/callback",
data: response,
success: function(data) {
// response from server
}
});
} else {
// google authentication failed
}
});
});
};