Skip to content

Commit

Permalink
Use auth2 instead of auth
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumev committed Dec 18, 2017
1 parent 8ef4b9e commit 2f98198
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
33 changes: 16 additions & 17 deletions dist/google-picker.js
Expand Up @@ -61,8 +61,8 @@
/**
* Load required modules
*/
function instanciate () {
gapi.load('auth', { 'callback': onApiAuthLoad });
function instantiate () {
gapi.load('auth2', { 'callback': onApiAuthLoad });
gapi.load('picker');
}

Expand All @@ -71,17 +71,18 @@
* If user is already logged in, then open the Picker modal
*/
function onApiAuthLoad () {
var authToken = gapi.auth.getToken();

if (authToken) {
handleAuthResult(authToken);
} else {
gapi.auth.authorize({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes,
'immediate' : false
}, handleAuthResult);
}
gapi.auth2.init({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes
})
.then(function (authInstance) {
return authInstance.signIn();
})
.then(function (guser) {
var response = guser.getAuthResponse();
accessToken = response.access_token;
openDialog();
});
}

/**
Expand Down Expand Up @@ -139,11 +140,9 @@
});
}

gapi.load('auth');
gapi.load('picker');

element.bind('click', function (e) {
instanciate();
/* dynamically load dependencies only on click */
instantiate();
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/google-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/google-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions src/google-picker.js
Expand Up @@ -62,7 +62,7 @@
* Load required modules
*/
function instantiate () {
gapi.load('auth', { 'callback': onApiAuthLoad });
gapi.load('auth2', { 'callback': onApiAuthLoad });
gapi.load('picker');
}

Expand All @@ -71,17 +71,18 @@
* If user is already logged in, then open the Picker modal
*/
function onApiAuthLoad () {
var authToken = gapi.auth.getToken();

if (authToken) {
handleAuthResult(authToken);
} else {
gapi.auth.authorize({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes,
'immediate' : false
}, handleAuthResult);
}
gapi.auth2.init({
'client_id' : lkGoogleSettings.clientId,
'scope' : lkGoogleSettings.scopes
})
.then(function (authInstance) {
return authInstance.signIn();
})
.then(function (guser) {
var response = guser.getAuthResponse();
accessToken = response.access_token;
openDialog();
});
}

/**
Expand Down

0 comments on commit 2f98198

Please sign in to comment.