Skip to main content

Generating a Bearer Token

This document provides instructions on how to generate a bearer token using the client credentials grant, a common method for obtaining an access token without user authentication.

Prerequisites

Before generating a bearer token, ensure that you have the following information ready:

  • Client ID: A unique identifier for your application.
  • Client Secret: A confidential key for your application.

Step 1: Prepare the Request

To generate a bearer token, you need to send an HTTP POST request to the token endpoint.

curl --request POST \
--url https://identity.walr.com/oauth/token \
--header 'content-type: application/json' \
--data '{
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"audience": "https://api.walr.com",
"grant_type": "client_credentials"
}'

In this request, replace the following placeholders:

  • YOUR_CLIENT_ID: Your application's unique client ID.
  • YOUR_CLIENT_SECRET: Your application's client secret.

Step 2: Send the Request

Execute the prepared HTTP POST request to the token endpoint. This request includes your client credentials and the target audience.

Step 3: Receive the Bearer Token

Upon a successful request, you will receive a JSON response containing an access token, typically in the access_token field.

Here is an example response:

{
"access_token": "YOUR_ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600
}

Step 4: Use the Bearer Token

You can use the obtained bearer token to access the protected API or resource by including it in the Authorization header of your HTTP requests. For example:

GET /api/resource HTTP/1.1
Host: api.walr.com
Authorization: Bearer YOUR_ACCESS_TOKEN

Congratulations! You have successfully generated a bearer token using the client credentials grant. You can now use this token to access the protected API or resource.

Remember to keep your client credentials (client ID and client secret) and bearer token secure and do not share them publicly.