Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ callback | `[provider]` | final callback route on your server to receive the [re
dynamic | `[provider]` | allow [dynamic override](#dynamic-override) of configuration
overrides | `[provider]` | [static overrides](#static-overrides) for a provider
response | `[provider]` | [limit](#limit-response-data) the response data
token_endpoint_auth_method | `[provider]` | Authentication method for the token endpoint from [RFC 7591](https://tools.ietf.org/html/rfc7591#section-2)
name | generated | provider's [name](#grant), used to generate `redirect_uri`
[provider] | generated | provider's [name](#grant) as key
redirect_uri | generated | OAuth app [redirect URI](#redirect-uri), generated using `protocol`, `host`, `path` and `name`
Expand Down
1 change: 1 addition & 0 deletions config/reserved.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"oauth",
"scope_delimiter",
"custom_parameters",
"token_endpoint_auth_method",

"protocol",
"host",
Expand Down
9 changes: 9 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ var format = {
return Object.keys(overrides).length ? overrides : undefined
},

// https://tools.ietf.org/html/rfc7591#section-2
token_endpoint_auth_method: ({oauth, token_endpoint_auth_method}) => {
// There is no `none` method since it's used only with public clients
var defaults = ['client_secret_post', 'client_secret_basic']

return oauth === 2
? defaults.includes(token_endpoint_auth_method) ? token_endpoint_auth_method : defaults[0]
: undefined
}
}

var state = (provider, key = 'state', value = provider[key]) =>
Expand Down
4 changes: 3 additions & 1 deletion lib/flow/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ exports.access = (provider, authorize, session) => new Promise((resolve, reject)
client_secret: provider.secret
}
}
if (/ebay|fitbit2|homeaway|hootsuite|reddit/.test(provider.name)) {
if (/ebay|fitbit2|homeaway|hootsuite|reddit/.test(provider.name)
|| provider.token_endpoint_auth_method === 'client_secret_basic'
) {
delete options.form.client_id
delete options.form.client_secret
options.auth = {user: provider.key, pass: provider.secret}
Expand Down
14 changes: 14 additions & 0 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ describe('config', () => {
t.equal(config.format.secret({oauth: 3, secret: 'secret'}), undefined)
t.equal(config.format.secret({}), undefined)
})
it('token_endpoint_auth_method', () => {
t.equal(config.format.token_endpoint_auth_method({}), undefined)
t.equal(config.format.token_endpoint_auth_method({oauth: undefined}), undefined)
t.equal(config.format.token_endpoint_auth_method({oauth: 1}), undefined)
t.equal(config.format.token_endpoint_auth_method({oauth: 2}), 'client_secret_post')
t.equal(config.format.token_endpoint_auth_method({oauth: 2, token_endpoint_auth_method: 'foo'}), 'client_secret_post')
t.equal(config.format.token_endpoint_auth_method({oauth: 2, token_endpoint_auth_method: 'client_secret_basic'}), 'client_secret_basic')
t.equal(config.format.token_endpoint_auth_method({oauth: 2, token_endpoint_auth_method: 'client_secret_post'}), 'client_secret_post')
})
it('scope', () => {
t.equal(config.format.scope({scope: []}), undefined)
t.equal(config.format.scope({scope: ['']}), undefined)
Expand Down Expand Up @@ -243,6 +252,7 @@ describe('config', () => {
{
protocol: 'http',
host: 'localhost:3000',
token_endpoint_auth_method: 'client_secret_post',
oauth: 2,
client_id: 'key',
client_secret: 'secret',
Expand All @@ -255,6 +265,7 @@ describe('config', () => {
sub: {
protocol: 'http',
host: 'localhost:3000',
token_endpoint_auth_method: 'client_secret_post',
oauth: 2,
client_id: 'key',
client_secret: 'secret',
Expand Down Expand Up @@ -285,6 +296,7 @@ describe('config', () => {
facebook: {
authorize_url: 'https://www.facebook.com/dialog/oauth',
access_url: 'https://graph.facebook.com/oauth/access_token',
token_endpoint_auth_method: 'client_secret_post',
oauth: 2,
protocol: 'http',
host: 'localhost:3000',
Expand All @@ -307,6 +319,7 @@ describe('config', () => {
facebook: {
authorize_url: 'https://www.facebook.com/dialog/oauth',
access_url: 'https://graph.facebook.com/oauth/access_token',
token_endpoint_auth_method: 'client_secret_post',
oauth: 2,
protocol: 'http',
host: 'localhost:3000',
Expand Down Expand Up @@ -344,6 +357,7 @@ describe('config', () => {
config.provider(options, session), {
authorize_url: 'https://www.facebook.com/dialog/oauth',
access_url: 'https://graph.facebook.com/oauth/access_token',
token_endpoint_auth_method: 'client_secret_post',
oauth: 2,
dynamic: true,
name: 'facebook',
Expand Down