Skip to content

fix(basecamp): type parameter #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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