> For the complete documentation index, see [llms.txt](https://docs.toucanai.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.toucanai.cloud/embed/authentication/authentication-models.md).

# Authentication models

{% hint style="info" %}
**Target Audience**: Developers
{% endhint %}

### TL;DR

Toucan AI utilizes server-side token generation to authorize user access and enforce data isolation for embedded components.

***

### When to use this

Use this page to understand the technical workflow for securing embedded dashboards and the AI assistant, ensuring each user only accesses authorized data.

***

### Purpose of Authentication

Authentication establishes a secure link between the host application and Toucan AI. It serves two primary functions:

* **Access Control**: Verifies that a user is authorized to view specific dashboards, charts, or the AI assistant.
* **Data Scoping**: Enables Row-Level Security (RLS) and multi-tenant isolation by passing user context from the host application to Toucan AI.

***

### Token-Based Authentication

This is the standard model for production environments. It relies on a secure handshake between your backend and the Toucan AI API.

**Technical Workflow**

1. **Identity Verification**: Your application authenticates the user through your existing system (e.g., SSO, OAuth, or JWT).
2. **Token Generation**: Your backend requests a signed session token from Toucan AI using a secure API key. This token encodes the user identity and custom attributes like `organization_id` or `region`.
3. **Frontend Delivery**: The backend passes this token to the frontend, where it is injected into the `<tc-dashboard>` or `<tc-ai-assistant>` web component.
4. **Validation**: Toucan AI validates the token signature and enforces the associated RLS rules during data execution.

**Use Case Suitability**

* **Multi-tenant SaaS**: Essential for isolating customer data within shared database schemas.
* **Production Environments**: Required for any scenario where API keys must be protected from client-side exposure.
* **Dynamic Scoping**: Best for applications where data access changes frequently based on user roles or departments.

<figure><img src="/files/KvEYoib3jOZmV6a4A2K9" alt="Authentication Flow"><figcaption></figcaption></figure>

***

### Security Best Practices

* **Server-Side Execution**: Always generate and sign tokens on your backend; never expose API keys or signing secrets in client-side code.
* **Token Expiration**: Implement short-lived tokens to minimize the impact of potential session compromise.
* **Credential Rotation**: Regularly rotate API keys within the Toucan AI settings to maintain platform security.
* **Minimalist Attributes**: Include only the specific attributes required for access control and RLS to maintain efficient token payloads.


---

# 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:

```
GET https://docs.toucanai.cloud/embed/authentication/authentication-models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
