Skip to content

Commit 43c4fc4

Browse files
author
Roman Minkin
committed
Add authentication method for the token endpoint
1 parent 8c9eed4 commit 43c4fc4

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ callback | `[provider]` | final callback route on your server to receive the [re
526526
dynamic | `[provider]` | allow [dynamic override](#dynamic-override) of configuration
527527
overrides | `[provider]` | [static overrides](#static-overrides) for a provider
528528
response | `[provider]` | [limit](#limit-response-data) the response data
529+
token_endpoint_auth_method | `[provider]` | Authentication method for the token endpoint from [RFC 7591](https://tools.ietf.org/html/rfc7591#section-2)
529530
name | generated | provider's [name](#grant), used to generate `redirect_uri`
530531
[provider] | generated | provider's [name](#grant) as key
531532
redirect_uri | generated | OAuth app [redirect URI](#redirect-uri), generated using `protocol`, `host`, `path` and `name`

config/reserved.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"oauth",
66
"scope_delimiter",
77
"custom_parameters",
8+
"token_endpoint_auth_method",
89

910
"protocol",
1011
"host",

lib/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ var format = {
137137
return Object.keys(overrides).length ? overrides : undefined
138138
},
139139

140+
// https://tools.ietf.org/html/rfc7591#section-2
141+
token_endpoint_auth_method: ({oauth, token_endpoint_auth_method}) => {
142+
// There is no `none` method since it's used only with public clients
143+
var defaults = ['client_secret_post', 'client_secret_basic']
144+
145+
return oauth === 2
146+
? defaults.includes(token_endpoint_auth_method) ? token_endpoint_auth_method : defaults[0]
147+
: undefined
148+
}
140149
}
141150

142151
var state = (provider, key = 'state', value = provider[key]) =>

lib/flow/oauth2.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ exports.access = (provider, authorize, session) => new Promise((resolve, reject)
7878
client_secret: provider.secret
7979
}
8080
}
81-
if (/ebay|fitbit2|homeaway|hootsuite|reddit/.test(provider.name)) {
81+
if (/ebay|fitbit2|homeaway|hootsuite|reddit/.test(provider.name)
82+
|| provider.token_endpoint_auth_method === 'client_secret_basic'
83+
) {
8284
delete options.form.client_id
8385
delete options.form.client_secret
8486
options.auth = {user: provider.key, pass: provider.secret}

test/config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ describe('config', () => {
8282
t.equal(config.format.secret({oauth: 3, secret: 'secret'}), undefined)
8383
t.equal(config.format.secret({}), undefined)
8484
})
85+
it('token_endpoint_auth_method', () => {
86+
t.equal(config.format.token_endpoint_auth_method({}), undefined)
87+
t.equal(config.format.token_endpoint_auth_method({oauth: undefined}), undefined)
88+
t.equal(config.format.token_endpoint_auth_method({oauth: 1}), undefined)
89+
t.equal(config.format.token_endpoint_auth_method({oauth: 2}), 'client_secret_post')
90+
t.equal(config.format.token_endpoint_auth_method({oauth: 2, token_endpoint_auth_method: 'foo'}), 'client_secret_post')
91+
t.equal(config.format.token_endpoint_auth_method({oauth: 2, token_endpoint_auth_method: 'client_secret_basic'}), 'client_secret_basic')
92+
t.equal(config.format.token_endpoint_auth_method({oauth: 2, token_endpoint_auth_method: 'client_secret_post'}), 'client_secret_post')
93+
})
8594
it('scope', () => {
8695
t.equal(config.format.scope({scope: []}), undefined)
8796
t.equal(config.format.scope({scope: ['']}), undefined)
@@ -243,6 +252,7 @@ describe('config', () => {
243252
{
244253
protocol: 'http',
245254
host: 'localhost:3000',
255+
token_endpoint_auth_method: 'client_secret_post',
246256
oauth: 2,
247257
client_id: 'key',
248258
client_secret: 'secret',
@@ -255,6 +265,7 @@ describe('config', () => {
255265
sub: {
256266
protocol: 'http',
257267
host: 'localhost:3000',
268+
token_endpoint_auth_method: 'client_secret_post',
258269
oauth: 2,
259270
client_id: 'key',
260271
client_secret: 'secret',
@@ -285,6 +296,7 @@ describe('config', () => {
285296
facebook: {
286297
authorize_url: 'https://www.facebook.com/dialog/oauth',
287298
access_url: 'https://graph.facebook.com/oauth/access_token',
299+
token_endpoint_auth_method: 'client_secret_post',
288300
oauth: 2,
289301
protocol: 'http',
290302
host: 'localhost:3000',
@@ -307,6 +319,7 @@ describe('config', () => {
307319
facebook: {
308320
authorize_url: 'https://www.facebook.com/dialog/oauth',
309321
access_url: 'https://graph.facebook.com/oauth/access_token',
322+
token_endpoint_auth_method: 'client_secret_post',
310323
oauth: 2,
311324
protocol: 'http',
312325
host: 'localhost:3000',
@@ -344,6 +357,7 @@ describe('config', () => {
344357
config.provider(options, session), {
345358
authorize_url: 'https://www.facebook.com/dialog/oauth',
346359
access_url: 'https://graph.facebook.com/oauth/access_token',
360+
token_endpoint_auth_method: 'client_secret_post',
347361
oauth: 2,
348362
dynamic: true,
349363
name: 'facebook',

0 commit comments

Comments
 (0)