How to pass a Bearer token in Rest assured?

Published On: 15 May 2023.By .
  • Quality Engineering

What is the Authorization Header?

The Authorization request header includes credentials to authenticate the client on the server. HTTP provides a built-in framework for user authentication and controlling access to protected resources

Bearer token

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 drop-down list. In the Token field, enter your API key value. For added security, store it in a variable and reference the variable by name.Postman will append the token value to the text Bearer in the required format to the request Authorization header.

Bearer Token Authentication Example

Authorization: Bearer {token}

Sending Request with Bearer Token Authorization Header

To send a request with a Bearer Token authorization header, you need to make an HTTP GET or POST request and provide your Bearer Token with the Authorization: Bearer {token} HTTP header. Bearer Authentication (also called token authentication) is an HTTP authentication scheme created as part of OAuth 2.0 but is now used on its own. For security reasons, bearer tokens are only sent over HTTPS (SSL). 


 Response response = given().header((“Authorization”,”Bearer “+token)

Related content

Got an Idea?

Let’s create a better tomorrow together