> ## Documentation Index
> Fetch the complete documentation index at: https://rasa.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Authorizing Studio Requests

> How to setup authorization for the Studio API

## Introduction

Learn how to obtain the secret and client ID required for authenticating requests to Studio API. API is built using GraphQL, enabling powerful querying and mutations for flexible interaction with Studio API. For authentication, we rely on Keycloak to manage users and secure external communication by using OpenID Connect's "Client Credentials Flow".

### Studio-External Client Overview

The **studio-external** client is a default client in Keycloak for facilitating API integrations with Rasa Studio. This client is pre-configured with roles, ready for use without additional configuration.

Customers can use **studio-external** to:

* Manage conversations via APIs,
* Request urls to artifacts for CI/CD

This flexibility allows for quick integration or custom setups based on specific requirements.

**Note**: The instructions below cover both using the default client and creating a new one. If you decide to use existing **studio-external**, login to Keycloak admin and skip directly to [Obtain Client ID and Secret](/docs/studio/security/authorization#obtaining-client-id-and-secret)

## Creating a New Client ID

To create a new Client ID in Keycloak, follow these steps:

1. Go to Keycloak Admin and log in.
   **Note**: Ensure the **rasa-studio** realm is selected from the top-left dropdown.
   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-realm.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=3d2e8b946c03fdf8b95243a2a02fe740" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-realm.png" />
2. Navigate to the **Clients** tab and click **Create**.

   * Set **Client ID** to a name of you choice.
   * Set **Client type** to **OpenID Connect**.
   * Click **Next**.

   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-create-clientid.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=978e7bf5b1e62baeef1282a098068522" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-create-clientid.png" />

   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-client-type-clientid.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=fd6200046a4401a63a2a977917154e4b" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-client-type-clientid.png" />

### Client Capability Configuration

1. On the **Capability Config** page, enable:

   * **Client Authentication**.
   * **Service Account Roles** (for **Client Credentials Flow**).

   **Warning**: Keep other settings off.

   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-capability-configuration.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=9c69db4ec058618710cf7846935fa140" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-capability-configuration.png" />
2. Click **Next**.

### Login Settings

On this page click **Save** to finish.

### Assigning a Role to the Client

1. Go to **Service Accounts Roles** and click on `service-account-studio-external`.
   **Note:** This service account user may have a different name depending on how you name your client.
   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-service-account.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=594baa520e4266c89f63d0354a7111fc" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-service-account.png" />
2. In the **Role Mapping** tab, assign a role to your Client, e.g. **Manage conversations** to enable managing conversations via the API.

   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-service-account-roles.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=abb5c3a6cde8c52bc1ec127b52166047" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-service-account-roles.png" />

   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-assign-role.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=7591c475be5530f6d278b287139762b0" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-assign-role.png" />

### Obtaining Client ID and Secret

1. Return to the **Clients** tab, make sure the **rasa-studio** realm is selected, select your client, and go to the **Credentials** tab.
2. Click on Regenerate next to the Client Secret field to enhance security.
3. Make sure to note down the new **Client ID** and **Client Secret** for future use.

   <img src="https://mintcdn.com/rasa-43f32701/XHj2VCWI4cZ6KSTn/images/legacy/studio/security/api-keycloak-clientid-and-secret.png?fit=max&auto=format&n=XHj2VCWI4cZ6KSTn&q=85&s=394c813eb34dbffaab36d9164532aaf6" alt="image" width="2648" height="1496" data-path="images/legacy/studio/security/api-keycloak-clientid-and-secret.png" />

### Obtain access token

To perform API requests, you must first obtain an access token using a **POST** request.

1. Create a **POST** request to:

https\://\{your-keycloak-address}/auth/realms/rasa-studio/protocol/openid-connect/token

For example, in a local environment, the URL is:

```plaintext theme={null}
https://localhost:8081/auth/realms/rasa-studio/protocol/openid-connect/token
```

2. Set **x-www-form-urlencoded** body parameters:
   * `grant_type`: `client_credentials`,
   * `client_id`: your new Client ID name,
   * `client_secret`: the secret obtained from [Obtain Client ID and Secret](/docs/studio/security/authorization#obtaining-client-id-and-secret)

#### Example curl Request

```bash theme={null}
curl -X POST https://localhost:8081/auth/realms/rasa-studio/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'grant_type=client_credentials&client_id=<your-client-id>&client_secret=<your-client-secret>'
```

You should receive an *access\_token*.

Now, using this token as the **Authorization: Bearer *retrieved\_token*** header, you can send your API requests.


## Related topics

- [Studio Architecture](/docs/reference/architecture/studio.md)
- [Studio Environment Variables](/docs/reference/config/studio-environment-variables.md)
- [Studio Change Log](/docs/reference/changelogs/studio-changelog.md)
- [Studio Infrastructure Requirements](/docs/reference/deployment/studio-hardware-requirements.md)
- [Your First Assistant](/docs/studio/tutorial.md)
