# How to get authorization token

**URL:** <https://community.bluescape.com/t/how-to-get-authorization-token/4981>\
**Category:** Developer\
**Created:** [October 10, 2023, 8:09pm UTC](https://community.bluescape.com/t/how-to-get-authorization-token/4981 "2023-10-10T20:09:09Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![kkoechley](https://sea1.discourse-cdn.com/bluescape/user_avatar/community.bluescape.com/kkoechley/32/2474_2.png) [@kkoechley](https://community.bluescape.com/u/kkoechley)\
**Post date:** [October 12, 2023, 9:05pm UTC](https://community.bluescape.com/t/how-to-get-authorization-token/4981/4 "2023-10-12T21:05:11Z")

</div>

Hi @Sathish,

Thanks for the clarification. You can get a bearer token using OAuth2 in the same way the your web application is getting the bearer token.

You can use our new [OAuth2 v3](https://community.bluescape.com/t/migrating-existing-v2-api-application-to-v3-oauth2/3607) code flow, which follows the same structure as [v2 OAuth code flow](https://community.bluescape.com/t/api-application-authorization/2025).

OAuth Authorization URL:  
`https://api.apps.us.bluescape.com/v3/oauth2/authorize`

Authorization Token endpoint:  
`https://api.apps.us.bluescape.com/v3/oauth2/token`

**You will need to:**

1. [Create your application](https://client.apps.us.bluescape.com/my/profile) to get clientId/clientSecret with redirect to your server
2. In server code set, endpoint, scope, response\_type, etc

```auto
const base_API = "api.apps.us.bluescape.com";
const base_auth_url = `https://${base_API}/v3/oauth2/authorize`;
const token_endpoint = `https://${base_API}/v3/oauth2/token`;

const authType = "code";
const client_scope = "scope=v2legacy";
const client_id = "<yourClientId>";
const client_secret = "<yourAppSecret>";
const client_redirect = "http://localhost:3001/auth/callback";

```

1. In web browser (or URL redirect from server), make call to Bluescape authorization server with your application clientId and redirect URL:  
`https://api.apps.us.bluescape.com/v3/oauth2/authorize?response_type=code&client_id=<yourClientId>&redirect_uri=http://localhost:3001/auth/callback&scope=v2legacy%20offline_access`

2. After user authorizes access from UI presented from step3, access code is returned to `client_redirect`

3. Server uses token endpoint with returned `client_redirect` to get bearer token tied to the user that granted access

**example config:**

```auto
getBearerToken.axios.congig = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.apps.us.bluescape.com/v3/oauth2/token',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  data: URLSearchParams {
    'grant_type' => 'authorization_code',
    'client_id' => '<yourClientId>',
    'client_secret' => '<yourClientSecret>',
    'redirect_uri' => 'http://localhost:3001/auth/callback',
    'code' => '<yourAccessCodeReturnedFromAuthorizationCallback>' }
}

```

sample response with bearer token and refresh token:

```auto
{
  access_token: '<yourBearerToken>',
  expires_in: 3600,
  refresh_token: '<refreshTokenUsedToGetNewBearerToken>',
  scope: 'v2legacy',
  token_type: 'Bearer'
}

```

1. Server can continue to generate new bearer token from refresh token, so the manual authorization wouldn’t need to be done unless refresh token was expired (which I believe is one year)

You can then use the bearer token for subscription or any other API call.

Please let me know if you have any additional questions.

---

_[View the full topic](https://community.bluescape.com/t/how-to-get-authorization-token/4981)._
