-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOAuth2GService.gs
More file actions
35 lines (33 loc) · 1.16 KB
/
OAuth2GService.gs
File metadata and controls
35 lines (33 loc) · 1.16 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
var clientId="";
var clientSecret="";
function initOAuth2(clientId,clientSecret){
this.clientId=clientId;
this.clientSecret=clientSecret;
}
function getPhotoService() {
//refer to https://github.com/gsuitedevs/apps-script-oauth2
return OAuth2.createService('photoslibrary')
.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
.setClientId(this.clientId)
.setClientSecret(this.clientSecret)
.setCallbackFunction('authCallback')
.setPropertyStore(PropertiesService.getUserProperties())
.setScope('https://www.googleapis.com/auth/photoslibrary')
.setParam('login_hint', Session.getActiveUser().getEmail())
.setParam('access_type', 'offline')
.setParam('approval_prompt', 'force');
}
function authCallback(request) {
var photoService = getPhotoService();
var isAuthorized = photoService.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this tab.');
} else {
return HtmlService.createHtmlOutput('Denied. You can close this tab');
}
}
function logout() {
var service = getPhotoService();
service.reset();
}