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

# Get token

## Generating an Authentication Token

To allow your users to authenticate with our web app through the Clinch SDK, you need to generate an **authentication token**. This token should be created when the user initiates an action to open the Clinch web app via your iframe (e.g., a button click).

## **Steps to Generate the Authentication Token:**

1. **Server-Side Service**: The authentication token must be generated server-side to securely handle the **API key** that we provide. **Do not expose the API key** on the client-side to avoid security risks.
2. **Calling the Authentication Endpoint**: Your server should make a `POST` request to the following endpoint, including the user's metadata:

   ```arduino
   POST https://api.clinch.gg/v0/wager/operator/create-token
   ```

   **Request Body**:

   ```json
   {
     "userId": "<userId>",
     "displayName": "<userName>",
   }
   ```

   * `userId`: The unique ID of your user.
   * `displayName`: The display name of the user.

   **Request Header:**

   ```
   x-operator-id: your_operator_id
   x-api-key: your_api_key
   ```
3. **Response**: Upon successful authentication, the endpoint will return a token in the response:

   **Response Example**:

   ```json
   {
     "status": 200,
     "data": {
       "token": "eyJhbGciOiJSUzI1NiIsInR5cC..."
     }
   }
   ```
4. **Using the Token in the `getToken` Callback**: Once you receive the token in the server response, return this token in the `getToken` callback of the Clinch SDK. Here's an example:

   ```javascript
   function async getToken() {
     const response = await fetch('https://your-server.com/generate-token', {
       method: 'POST',
       headers: {
         'Content-Type': 'application/json',
       },
       body: JSON.stringify({
         userId: "user123",
         displayName: "John Doe",
         lightningAddress: "john@lightning.com"
       })
     });
     const data = await response.json();
     return data.token;
   }
   ```
