Yashvardhan Khaitan
Yashvardhan Khaitan

Reputation: 143

Authorization Bearer Token Header in Javascript

I am trying to create a header for an authorization bearer token that I generated from the API's side. I am using CORS-anywhere to call the API and get the data through JSON. I was wondering, what is the correct format for the authorization bearer token header?

Upvotes: 4

Views: 19763

Answers (2)

j4ckofalltrades
j4ckofalltrades

Reputation: 610

The HTTP Authorization has the following syntax:

Authorization: <type> <credentials>

For your particular use case i.e. using a Bearer Token the request header should be:

Authorization: Bearer <token>

Upvotes: 4

dwosk
dwosk

Reputation: 1257

Without any more information to go off of, typically an Authorization header that uses a bearer token should look like the following:

Authorization: Bearer mF_9.B5f-4.1JqM

In javascript, typically it involves setting the Authorization property of a headers object:

// headers you pass to a http request
let headers = {
   'Authorization': 'Bearer ' + token
};

Usually a http request library will taken in a parameter for headers somewhere that you would pass this to.

Is there something more specific you want to know?

Upvotes: 6

Related Questions