> For the complete documentation index, see [llms.txt](https://docs.hyperswitch.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hyperswitch.io/integrations/prism/node/merchant-authentication-service/create-access-token.md).

# Create Access Token

## Overview

The `createAccessToken` method generates a short-lived authentication token for accessing payment processor APIs. Use this for temporary, secure access without exposing long-lived credentials.

**Business Use Case:** Your frontend needs to initialize a payment widget. Generate a temporary token with limited scope and short expiry for client-side use.

## Purpose

| Scenario           | Benefit                           |
| ------------------ | --------------------------------- |
| Frontend SDKs      | Secure client-side initialization |
| Delegated access   | Scoped tokens for third parties   |
| Session-based auth | Time-limited access               |

## Request Fields

| Field       | Type   | Required | Description                               |
| ----------- | ------ | -------- | ----------------------------------------- |
| `scope`     | string | No       | Token scope (e.g., "payment:write")       |
| `expiresIn` | number | No       | Token lifetime in seconds (default: 3600) |

## Response Fields

| Field         | Type   | Description                          |
| ------------- | ------ | ------------------------------------ |
| `accessToken` | string | The token string to use in API calls |
| `tokenType`   | string | Bearer                               |
| `expiresIn`   | number | Seconds until expiry                 |
| `expiresAt`   | string | ISO 8601 expiry timestamp            |
| `statusCode`  | number | HTTP status code                     |

## Example

### SDK Setup

```javascript
const { MerchantAuthenticationClient } = require('hyperswitch-prism');

const authClient = new MerchantAuthenticationClient({
    connector: 'stripe',
    apiKey: 'YOUR_API_KEY',
    environment: 'SANDBOX'
});
```

### Request

```javascript
const request = {
    scope: "payment:write",
    expiresIn: 3600
};

const response = await authClient.createAccessToken(request);
```

### Response

```javascript
{
    accessToken: "sk_test_xxx",
    tokenType: "Bearer",
    expiresIn: 3600,
    expiresAt: "2024-01-15T11:30:00Z",
    statusCode: 200
}
```

## Security Best Practices

* Use short expiry times (1 hour or less)
* Transmit only over HTTPS
* Never store tokens client-side long-term
* Implement token refresh logic

## Next Steps

* [createSessionToken](/integrations/prism/node/merchant-authentication-service/create-session-token.md) - Create session tokens for multi-step flows
* [Payment Service](/integrations/prism/node/payment-service.md) - Use tokens for payment operations


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hyperswitch.io/integrations/prism/node/merchant-authentication-service/create-access-token.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
