Skip to content

Commit

Permalink
Merge pull request #6692 from intelradoux/develop
Browse files Browse the repository at this point in the history
[NEW] Use tokenSentVia parameter for clientid/secret to token endpoint
  • Loading branch information
engelgabriel authored Apr 18, 2017
2 parents 6742e80 + 56c1eb9 commit 6dc77da
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions packages/rocketchat-custom-oauth/custom_oauth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,30 @@ export class CustomOAuth {
}

let response = undefined;

const allOptions = {
headers: {
'User-Agent': this.userAgent, // http://doc.gitlab.com/ce/api/users.html#Current-user
Accept: 'application/json'
},
params: {
code: query.code,
redirect_uri: OAuth._redirectUri(this.name, config),
grant_type: 'authorization_code',
state: query.state
}
};

// Only send clientID / secret once on header or payload.
if (this.tokenSentVia === 'header') {
allOptions['auth'] = `${ config.clientId }:${ OAuth.openSecret(config.secret) }`;
} else {
allOptions['params']['client_secret'] = OAuth.openSecret(config.secret);
allOptions['params']['client_id'] = config.clientId;
}

try {
response = HTTP.post(this.tokenPath, {
auth: `${ config.clientId }:${ OAuth.openSecret(config.secret) }`,
headers: {
Accept: 'application/json',
'User-Agent': this.userAgent
},
params: {
code: query.code,
client_id: config.clientId,
client_secret: OAuth.openSecret(config.secret),
redirect_uri: OAuth._redirectUri(this.name, config),
grant_type: 'authorization_code',
state: query.state
}
});
response = HTTP.post(this.tokenPath, allOptions);
} catch (err) {
const error = new Error(`Failed to complete OAuth handshake with ${ this.name } at ${ this.tokenPath }. ${ err.message }`);
throw _.extend(error, {response: err.response});
Expand Down

0 comments on commit 6dc77da

Please sign in to comment.