question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set an authorisation header?

See original GitHub issue

Hi. 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:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
kadamwhitecommented, May 17, 2017

@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.

1reaction
kadamwhitecommented, May 17, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found