Skip to content

Commit 9499dba

Browse files
authored
fix(basecamp): type parameter (#427)
* fix: type parameter * chore: lint
1 parent 91d7aa3 commit 9499dba

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

samples/Basecamp.gs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ function reset() {
3535
function getService_() {
3636
return OAuth2.createService('Basecamp')
3737
// Set the endpoint URLs.
38-
.setAuthorizationBaseUrl(
39-
'https://launchpad.37signals.com/authorization/new?type=web_server')
40-
.setTokenUrl(
41-
'https://launchpad.37signals.com/authorization/token?type=web_server')
38+
.setAuthorizationBaseUrl('https://launchpad.37signals.com/authorization/new')
39+
.setTokenUrl('https://launchpad.37signals.com/authorization/token')
40+
41+
// Set the required type param
42+
.setParam('type', 'web_server')
4243

4344
// Set the client ID and secret.
4445
.setClientId(CLIENT_ID)
@@ -49,7 +50,11 @@ function getService_() {
4950
.setCallbackFunction('authCallback')
5051

5152
// Set the property store where authorized tokens should be persisted.
52-
.setPropertyStore(PropertiesService.getUserProperties());
53+
.setPropertyStore(PropertiesService.getUserProperties())
54+
55+
// Set the handler for adding Basecamp's required type parameter to the
56+
// payload:
57+
.setTokenPayloadHandler(basecampTokenHandler);
5358
}
5459

5560
/**
@@ -65,6 +70,23 @@ function authCallback(request) {
6570
}
6671
}
6772

73+
/**
74+
* Adds the Basecamp API's required type parameter to the access token
75+
* request payload.
76+
*/
77+
function basecampTokenHandler(payload) {
78+
// If it's refresh request from library
79+
if (payload.grant_type === 'refresh_token') {
80+
// Basecamp refresh token API returns error if type is not specified
81+
payload.type = 'refresh';
82+
} else {
83+
// Basecamp token API returns error if type is not specified
84+
payload.type = 'web_server';
85+
}
86+
87+
return payload;
88+
}
89+
6890
/**
6991
* Logs the redict URI to register.
7092
*/

0 commit comments

Comments
 (0)