Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to set auth header name #301

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/core/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default class Auth {
constructor (ctx, options) {
this.ctx = ctx
this.options = options

this.authHeaderName = options.authHeader || 'Authorization';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for the authHeader option, strategies have an option called tokenName.
Using that option will solve the problem

     this.authHeaderName = strategy.options.tokenName || 'Authorization'


// Strategies
this.strategies = {}
Expand Down Expand Up @@ -265,8 +267,8 @@ export default class Auth {
if (!_endpoint.headers) {
_endpoint.headers = {}
}
if (!_endpoint.headers['Authorization'] && isSet(token) && token) {
_endpoint.headers['Authorization'] = token
if (!_endpoint.headers[this.authHeaderName] && isSet(token) && token) {
_endpoint.headers[this.authHeaderName] = token
}

return this.request(_endpoint)
Expand Down