How to set an authorisation header?
See original GitHub issueHi. I’m most likely getting something very basic wrong, but I can’t put my finger on it.
I’ve got a JWT token that I’d like to set for my requests but superagent’s set
doesn’t seem to work. Currently I get the following error:
TypeError: _endpoints2.default.pages(...).set is not a function
How would I go about setting the token? I saw headers
in the docs, would that be it (and does it take an Object
or something else)? Is there a way to set it for all requests by default (a custom transport maybe)?
import wp from './endpoints'; // I just export a new WPAPI() with some custom endpoints
import AuthService from './AuthenticationService';
let token = '';
AuthService.getAccessToken().then(webToken => {
token = webToken;
});
export const getPages = () => wp.pages()
.set('Authorization', 'Bearer ' + token)
// .headers('Authorization', 'Bearer ' + token) // How would the headers() format look?
.param('per_page', '80')
.then(response => {
return response;
}).catch(err => {
console.log('ERR! Could not retrieve pages:', err);
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:9
Top Results From Across the Web
Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >http post - how to send Authorization header? - Stack Overflow
You configure it like this: updateProfileInformation(user: User) { var headers = new Headers(); headers.append('Content-Type', ...
Read more >Generate an Authorization Header - Alert Logic Docs
Generate an Authorization Header · In the command line, type the following command, including the single quotation marks: echo -n '<user_name>:< ...
Read more >HTTP headers: Authorization header | Web Services Tutorial
HTTP headers : Cookie header | Web Services Tutorial · how to pass authorization header / JWT Token in angular services | consume...
Read more >How do I send a request with Authorization Bearer Header?
To send a request with the Bearer Token authorization header, you need to make an HTTP request and provide your Bearer Token in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mzalewski @andreasvirkus I’ve proposed a system for specifying custom headers in pull request #315 and I would welcome your feedback on the implementation and interface.
Hey y’all, apologies for letting this sit so long without response. We’re evaluating supporting JWT natively but I will also be working on an update that includes a new method to set the headers to use on your request, which should make third-party support for JWT and other header-based authentication schemes much easier. I’ll drop the PR link here for comments once I have something ready