devour-js/devour-client

Support Bearer Tokens (e.g. JWT)

StephanMeijer opened this issue · 6 comments

Support for authentication through for example jwt tokens:

Authorization: Bearer ...........

Will write this myself

You can set headers directly on the devour instance, does that work for you?

const jsonApi = new JsonApi({apiUrl: 'http://your-api-here.com'})

// Append headers to every request
jsonApi.headers['Authorization'] = `Bearer ${token}`

that works, but why is Basic auth being handled as a first class citizen, but Bearer is not?

The underlying library axios treats basic as first-class citizen. https://github.com/axios/axios

Should be easy enough to implement bearer token.

https://github.com/twg/devour/blob/master/src/middleware/json-api/req-http-basic-auth.js

It would be nice to have a utility method to allow for Bearer tokens.

I wrote an implementation for this: #200

This has been merged.