Skip to content

Commit

Permalink
fix: get auth token correct when login with sso
Browse files Browse the repository at this point in the history
PR-URL: #50
Credit: @ShangguanQuail
Close: #50
Reviewed-by: @isaacs

EDIT(@isaacs): updated token in test so that it was more clear which one
was being selected.
  • Loading branch information
liuye.adam authored and isaacs committed May 20, 2021
1 parent 0108123 commit ec6609d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const getAuth = (uri, opts = {}) => {
if (forceAuth && !regKey) {
return new Auth({
scopeAuthKey: null,
token: forceAuth._authToken,
token: forceAuth._authToken || forceAuth.token,
username: forceAuth.username,
password: forceAuth._password || forceAuth.password,
auth: forceAuth._auth || forceAuth.auth,
Expand Down
30 changes: 30 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ t.test('forceAuth', t => {
.then(res => t.equal(res, 'success', 'used forced auth details'))
})

t.test('forceAuth token', t => {
const config = {
registry: 'https://my.custom.registry/here/',
token: 'deadbeef',
'always-auth': false,
'//my.custom.registry/here/:_authToken': 'c0ffee',
'//my.custom.registry/here/:token': 'nope',
forceAuth: {
token: 'cafebad',
},
}
t.same(getAuth(config.registry, config), {
scopeAuthKey: null,
isBasicAuth: false,
token: 'cafebad',
auth: null,
}, 'correct forceAuth token picked out')

const opts = Object.assign({}, OPTS, config)
tnock(t, opts.registry)
.matchHeader('authorization', auth => {
t.equal(auth[0], 'Bearer cafebad', 'got correct bearer token')
return auth[0] === 'Bearer cafebad'
})
.get('/hello')
.reply(200, '"success"')
return fetch.json('/hello', opts)
.then(res => t.equal(res, 'success', 'token forceAuth succeeded'))
})

t.test('_auth auth', t => {
const config = {
registry: 'https://my.custom.registry/here/',
Expand Down

0 comments on commit ec6609d

Please sign in to comment.