Skip to content

Commit

Permalink
fix(basecamp): type parameter (#427)
Browse files Browse the repository at this point in the history
* fix: type parameter

* chore: lint
  • Loading branch information
kospl committed Mar 16, 2023
1 parent 91d7aa3 commit 9499dba
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions samples/Basecamp.gs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ function reset() {
function getService_() {
return OAuth2.createService('Basecamp')
// Set the endpoint URLs.
.setAuthorizationBaseUrl(
'https://launchpad.37signals.com/authorization/new?type=web_server')
.setTokenUrl(
'https://launchpad.37signals.com/authorization/token?type=web_server')
.setAuthorizationBaseUrl('https://launchpad.37signals.com/authorization/new')
.setTokenUrl('https://launchpad.37signals.com/authorization/token')

// Set the required type param
.setParam('type', 'web_server')

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

// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getUserProperties());
.setPropertyStore(PropertiesService.getUserProperties())

// Set the handler for adding Basecamp's required type parameter to the
// payload:
.setTokenPayloadHandler(basecampTokenHandler);
}

/**
Expand All @@ -65,6 +70,23 @@ function authCallback(request) {
}
}

/**
* Adds the Basecamp API's required type parameter to the access token
* request payload.
*/
function basecampTokenHandler(payload) {
// If it's refresh request from library
if (payload.grant_type === 'refresh_token') {
// Basecamp refresh token API returns error if type is not specified
payload.type = 'refresh';
} else {
// Basecamp token API returns error if type is not specified
payload.type = 'web_server';
}

return payload;
}

/**
* Logs the redict URI to register.
*/
Expand Down

0 comments on commit 9499dba

Please sign in to comment.