-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAuth.js
38 lines (35 loc) · 1.1 KB
/
OAuth.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
// Written by Amit Agarwal www.ctrlq.org
function authorizeBox() {
var service = getBoxService_();
if (!service.hasAccess()) {
var authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL to authorize: %s',
authorizationUrl);
} else {
Logger.log('Your account is already authorized');
}
}
/**
* Configures the service.
*/
function getBoxService_() {
return OAuth2.createService('Box')
.setAuthorizationBaseUrl('https://app.box.com/api/oauth2/authorize')
.setTokenUrl('https://app.box.com/api/oauth2/token')
.setClientId(getClientId())
.setClientSecret(getClientSecret())
.setCallbackFunction(getCallbackFunction())
.setPropertyStore(PropertiesService.getUserProperties());
}
/**
* Handles the OAuth callback.
*/
function authCallback(request) {
var service = getBoxService_();
var authorized = service.handleCallback(request);
if (authorized) {
return HtmlService.createHtmlOutput('Your Google account is now connected to Box');
} else {
return HtmlService.createHtmlOutput('Sorry, the connection to Box was denied');
}
}