Skip to content

Commit 2aa349f

Browse files
authored
Merge pull request #1041 from stefangr/fix_for_1040
Do not depend the Authorization header on the token type.
2 parents 3c94692 + f691332 commit 2aa349f

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/execute.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ export function applySecurities({request, securities = {}, operation = {}, spec}
241241
const schema = securityDef[key]
242242
const {type} = schema
243243
const accessToken = token && token.access_token
244-
const tokenType = token && token.token_type
245244

246245
if (auth) {
247246
if (type === 'apiKey') {
@@ -259,7 +258,7 @@ export function applySecurities({request, securities = {}, operation = {}, spec}
259258
}
260259
}
261260
else if (type === 'oauth2') {
262-
result.headers.authorization = `${tokenType || 'Bearer'} ${accessToken}`
261+
result.headers.authorization = `Bearer ${accessToken}`
263262
}
264263
}
265264
}

test/execute.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,55 @@ describe('execute', () => {
924924
api_key: 'hello'
925925
})
926926
})
927+
928+
it('should use the correct authorization scheme with OAuth2', function() {
929+
const spec = {
930+
host: 'swagger.io',
931+
basePath: '/v1',
932+
security: [{oauth2app: []}],
933+
paths: {
934+
'/one': {
935+
get: {
936+
operationId: 'getMe',
937+
security: [{oauth2app: []}]
938+
}
939+
}
940+
},
941+
securityDefinitions: {
942+
oauth2app: {
943+
type: 'oauth2',
944+
flow: 'application',
945+
tokenUrl: 'https://swagger.io/oauth2/token',
946+
scopes: {
947+
read: 'read access'
948+
}
949+
}
950+
}
951+
}
952+
953+
const request = {
954+
url: 'http://swagger.io/v1/one',
955+
method: 'GET',
956+
query: {}
957+
}
958+
959+
const securities = {
960+
authorized: {
961+
oauth2app: {
962+
token: {
963+
access_token: 'one two',
964+
token_type: 'bearer'
965+
}
966+
}
967+
}
968+
}
969+
970+
const applySecurity = applySecurities({request, securities, operation: spec.paths['/one'].get, spec})
971+
972+
expect(applySecurity.headers).toEqual({
973+
authorization: 'Bearer one two'
974+
})
975+
})
927976
})
928977

929978
describe('parameterBuilders', function () {

0 commit comments

Comments
 (0)