devour-js / devour-client

Don't just consume your JSON API, Devour it...
https://www.npmjs.com/package/devour-client
ISC License
429 stars 90 forks source link

Support Bearer Tokens (e.g. JWT) #157

Closed StephanMeijer closed 5 years ago

StephanMeijer commented 6 years ago

Support for authentication through for example jwt tokens:

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

Will write this myself

spiderbites commented 6 years ago

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}`
StephanMeijer commented 6 years ago

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

billxinli commented 6 years ago

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

Auspicus commented 5 years ago

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

kevincoenegrachts commented 5 years ago

I wrote an implementation for this: https://github.com/twg/devour/pull/200

Auspicus commented 5 years ago

This has been merged.