johnbrett / hapi-auth-bearer-token

Simple Bearer authentication scheme plugin for hapi, accepts token by Header, Cookie or Query parameter.
MIT License
218 stars 46 forks source link

allowMultipleHeaders: true should allow read two headers as array in token #208

Closed hspatel09 closed 4 years ago

hspatel09 commented 4 years ago

allowMultipleHeaders: true should allow read two headers as array in token e.g.Authorization: Token1 AF6C74D1-BBB2-4171-8EE3-7BE9356EB018; Token2 12345678

should give me token array with token[0] AF6C74D1-BBB2-4171-8EE3-7BE9356EB018 and token[1] 12345678

johnbrett commented 4 years ago

This is not really enough information to do much here, are you saying it's not working as expected? Happy to take a PR with a broken test or fix to improve things here.

johnbrett commented 4 years ago

https://github.com/johnbrett/hapi-auth-bearer-token/blob/master/test/index.js#L257 you can see how multiple headers works here.

johnbrett commented 4 years ago

I won't be changing behaviour here to return an array, that's a breaking change, I'd need to understand a valid use case.

hspatel09 commented 4 years ago

I have server which requires two tokens lets say bearertoken and refreshtoken as request headers, I want to ready them one by one in method or in array created in validateFunc : validateAuth . How do I do that ? I modified you multiple header test case like this, const request = { method: 'GET', url: '/multiple_headers_enabled', headers: { bearer: 'AF6C74D1-BBB2-4171-8EE3-7BE9356EB018 ,refresh 12345678' } };

const validateAuth = (_token, next) => { // here i want _token.bearer = 'AF6C74D1-BBB2-4171-8EE3-7BE9356EB018' // and _token.refresh = '12345678' or something like this // right now i am only getting one value. I will try pull request and see });

johnbrett commented 4 years ago

Yeah we only return the specific token here:

https://github.com/johnbrett/hapi-auth-bearer-token/blob/master/lib/index.js#L65-L72

Easiest option might be to just clone this library, and you could update the linked lines here to return both tokens?