Skip to content

Commit c910317

Browse files
authored
Merge branch 'master' into bug/opid-safe-access
2 parents 29b7ed5 + 705812c commit c910317

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/execute/swagger2/build-request.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function applySecurities({request, securities = {}, operation = {}, spec}
6666
const schema = securityDef[key]
6767
const {type} = schema
6868
const accessToken = token && token.access_token
69-
const tokenType = token && token.token_type
69+
let tokenType = token && token.token_type
7070

7171
if (auth) {
7272
if (type === 'apiKey') {
@@ -84,7 +84,8 @@ export function applySecurities({request, securities = {}, operation = {}, spec}
8484
}
8585
}
8686
else if (type === 'oauth2' && accessToken) {
87-
result.headers.authorization = `${tokenType || 'Bearer'} ${accessToken}`
87+
tokenType = (!tokenType || tokenType.toLowerCase() === 'bearer') ? 'Bearer' : tokenType
88+
result.headers.authorization = `${tokenType} ${accessToken}`
8889
}
8990
}
9091
}

test/index-authorizations.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,47 @@ describe('(instance) #execute', function () {
175175
})
176176
})
177177

178+
it('should replace any occurrence of `bearer` with `Bearer`', function () {
179+
const spec = {
180+
securityDefinitions: {
181+
testBearer: {
182+
type: 'oauth2',
183+
}
184+
},
185+
paths: {
186+
'/pet': {
187+
get: {
188+
operationId: 'getPets',
189+
security: [{testBearer: []}]
190+
}
191+
}
192+
}
193+
}
194+
195+
const authorizations = {
196+
testBearer: {
197+
token: {
198+
token_type: 'BeArEr',
199+
access_token: 'one two'
200+
}
201+
}
202+
}
203+
204+
return Swagger({spec, authorizations}).then((client) => {
205+
const http = createSpy()
206+
client.execute({http, operationId: 'getPets'})
207+
expect(http.calls.length).toEqual(1)
208+
expect(http.calls[0].arguments[0]).toEqual({
209+
credentials: 'same-origin',
210+
headers: {
211+
authorization: 'Bearer one two'
212+
},
213+
method: 'GET',
214+
url: '/pet'
215+
})
216+
})
217+
})
218+
178219
it('should add global securites', function () {
179220
const spec = {
180221
securityDefinitions: {

0 commit comments

Comments
 (0)