> For the complete documentation index, see [llms.txt](https://docs.shadowcipher.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shadowcipher.in/endpoints/get-access-token.md).

# Get an access token

Exchange client credentials for an access token.

<mark style="color:blue;">`POST`</mark> `/api/oauth/token`

Returns a Bearer token that is valid for 30 minutes. No `Authorization` header is needed for this call.

## Request body

Send as `application/json` or `application/x-www-form-urlencoded`.

| Field           | Type   | Required | Description                               |
| --------------- | ------ | -------- | ----------------------------------------- |
| `client_id`     | string | Yes      | Your client's user name.                  |
| `client_secret` | string | Yes      | Your client secret.                       |
| `grant_type`    | string | No       | If sent, it must be `client_credentials`. |

## Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://app.shadowcipher.in/api/oauth/token \
  -H "Content-Type: application/json" \
  -d '{
    "grant_type": "client_credentials",
    "client_id": "acme-client",
    "client_secret": "s3cr3t-value"
  }'
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const res = await fetch("https://app.shadowcipher.in/api/oauth/token", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    grant_type: "client_credentials",
    client_id: process.env.BSA_CLIENT_ID,
    client_secret: process.env.BSA_CLIENT_SECRET,
  }),
});
const { access_token } = await res.json();
```

{% endtab %}

{% tab title="Java" %}

```java
HttpClient client = HttpClient.newHttpClient();
String body = """
    {"grant_type":"client_credentials","client_id":"%s","client_secret":"%s"}
    """.formatted(clientId, clientSecret);

HttpRequest req = HttpRequest.newBuilder()
    .uri(URI.create("https://app.shadowcipher.in/api/oauth/token"))
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(body))
    .build();

HttpResponse<String> res = client.send(req, HttpResponse.BodyHandlers.ofString());
```

{% endtab %}
{% endtabs %}

## Responses

{% tabs %}
{% tab title="200 OK" %}
Access token issued. The response has `Cache-Control: no-store`.

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiY2xpZW50X2lkIjoiYWNtZS1jbGllbnQifQ.sig",
  "token_type": "Bearer",
  "expires_in": 1800,
  "scope": "txn:initiate"
}
```

| Field          | Type    | Description                             |
| -------------- | ------- | --------------------------------------- |
| `access_token` | string  | The Bearer token.                       |
| `token_type`   | string  | Always `Bearer`.                        |
| `expires_in`   | integer | Seconds until the token expires (1800). |
| `scope`        | string  | `txn:initiate`                          |
| {% endtab %}   |         |                                         |

{% tab title="400" %}
Missing parameters or unsupported grant type.

```json
{
  "error": "invalid_request",
  "error_description": "client_id and client_secret are required"
}
```

{% endtab %}

{% tab title="401" %}
Unknown client, wrong secret, or inactive client.

```json
{
  "error": "invalid_client",
  "error_description": "Client authentication failed"
}
```

{% endtab %}

{% tab title="429" %}
Too many token requests. This endpoint allows 5 requests per minute. See [Rate limits](https://docs.shadowcipher.in/reference/rate-limits.md).
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.shadowcipher.in/endpoints/get-access-token.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
