question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAuth2 incorrect Authorization header

See original GitHub issue

I’m using the swagger-js code (within swagger-ui) against an OAuth2 implementation.

I run into some problems which in my opinion should be fixed within the swagger-js code.

From the OAuth2 token endpoint I get a response with the following data:

{
  "access_token":"access_token",
  "token_type":"bearer",
  "expires_in":3600,
  "refresh_token":"value of refresh token"
}

The swagger-js code makes a request with the following header: Authorization: bearer access_token

The OAuth2 implementation does not accept this header, because of the lowercase “bearer” scheme.

As per RFC 6749 section 4.2.2 the token_type value is case insensitive. So it can be bearer, Bearer, BeArEr, etc. But per RFC 6750 section 2.1 the Authorization header should have the authorization scheme ‘Bearer’.

The authorization scheme should not depend on the token_type returned when fetching an access token.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kanjiroushicommented, May 26, 2017

Just a comment for people stuck with this issue, you can write a middleware to transform the bearer to capital B so it can go through oauth-server authorisation

//transform the bearer token to bearer //https://github.com/swagger-api/swagger-js/issues/1040 app.use(function (req, res, next) { var matches = req.headers[“authorization”].match(/bearer\s(\S+)/); if(matches) { console.log(‘modifying authorization header to capital B’); req.headers[“authorization”]='Bearer '+matches[1]; } next(); });

2reactions
buunguyencommented, May 11, 2017

Looks like reverting the PR by @stefangr means a correctly implemented OAuth server will fail, which isn’t ideal. I think the top priority is ensuring correct implementations to work. Then it’s nice to support other implementations that don’t 100% comply to the specs. Would be great if it just works without any work from the library users, but if we have to introduce an option, that’s definitely something to consider.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Invalid authorization header format - Fitbit Community
The Authorization header must be set to Basic followed by a space, then the Base64 encoded string of your application's client id and...
Read more >
SOLVED: Issues with Invalid Authorization header, ch:service
I'd always start with using curl (or similar) on the command line - that should eliminate anything else in your code / your...
Read more >
OAuth 2.0 - Incorrect Authorization header value #1749 - GitHub
My auth server reports %3ETzkfU%3EdvoBVbn%3FEt%2C(Mot%3C%3ESK as the client secret when trying to obtain an access token through postman using ...
Read more >
Invalid Client Authorization header when trying to get token ...
This is my first cut and is rough but. var accessKey = ""; var secret = ""; var url = "https://account.api.here.com/oauth2/token"; ...
Read more >
OAuth 2.0 Errors - Help | Developer Portal for YouTrack and Hub
Possible reasons: Authorization header in response is not of the Bearer type. Also, a parameter in the token request may be mulformed or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found