Skip to content

Commit

Permalink
Parse OAS3 HTTP-Auth schemes case-insensitively
Browse files Browse the repository at this point in the history
According to the authors of the OAI spec [1] schemes are
case-insensitive. Even if they were not, the current checks against
lowercase versions of scheme names do not match the IANA registry's
canonical versions [2] which are "Basic" and "Bearer".

[1] OAI/OpenAPI-Specification#1880 (comment)
[2] https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml#table-authschemes
  • Loading branch information
asazernik committed May 6, 2020
1 parent d89a926 commit 264e6f4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/execute/oas3/build-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,15 @@ export function applySecurities({request, securities = {}, operation = {}, spec}
}
}
else if (type === 'http') {
if (schema.scheme === 'basic') {
const scheme = schema.scheme && schema.scheme.toLowerCase()
if (scheme === 'basic') {
const username = value.username || ''
const password = value.password || ''
const encoded = btoa(`${username}:${password}`)
result.headers.Authorization = `Basic ${encoded}`
}

if (schema.scheme === 'bearer') {
if (scheme === 'bearer') {
result.headers.Authorization = `Bearer ${value}`
}
}
Expand Down

0 comments on commit 264e6f4

Please sign in to comment.