Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API, passing bearer token to GET HTTP URL

I have a OAuth2 (bearer token), but how do I pass it to the endpoint? More precisely, how do I include the bearer token in the URL.

Example URL:

https://api.twitter.com/1.1/search/tweets.json?q=%23superbowl&result_type=recent

Example Bearer Token:

AAAAA5n0w5n0w5n0wMyL0ngBe4r4rT0k4n

How do I use my bearer token to authorize my requests?

Example Incorrect Usage:

https://api.twitter.com/1.1/search/tweets.json?q=%23superbowl&result_type=recent&bearer=AAAAA5n0w5n0w5n0wMyL0ngBe4r4rT0k4n

like image 577
Mike Avatar asked Dec 16 '19 12:12

Mike


People also ask

Can I pass Bearer Token in URL?

Don't pass bearer tokens in page URLs: Bearer tokens SHOULD NOT be passed in page URLs (for example, as query string parameters). Instead, bearer tokens SHOULD be passed in HTTP message headers or message bodies for which confidentiality measures are taken.

How do I pass a Bearer Token in API?

Bearer tokens enable requests to authenticate using an access key, such as a JSON Web Token (JWT). The token is a text string, included in the request header. In the request Authorization tab, select Bearer Token from the Type dropdown list. In the Token field, enter your API key value.


3 Answers

You can do it in two equivalent ways:

  • by using the URL access_token parameter:

    https://base.url?access_token=f4f4994a875f461ca4d7708b9e027df4
  • or by adding the Authorization header:

    Authorization: Bearer f4f4994a875f461ca4d7708b9e027df4

Note: Whether two or only one of these methods works sometimes depends on the specific implementation of the web application (including the services and libraries used to create it).

like image 82
simhumileco Avatar answered Oct 23 '22 22:10

simhumileco


https://YourApiUrl?access_token=0db69822-0d02-4c17-8c39-d3b818bee184

Append the valid bearer token as value to the key "access_token". This worked for me.

like image 3
santhosh kumar Avatar answered Oct 23 '22 22:10

santhosh kumar


On Postman go to:

  1. Authentication tab
  2. Select type: Bearer Token
  3. Paste in your Token

If you want it in the URL too like you mentioned, just pass it in as parameter in the GET request.

Postman bearer token screenshot

like image 2
Ud0 Avatar answered Oct 23 '22 23:10

Ud0