# Authentication

Metra currently supports authentication exclusively through **Keycloak**.

Supported:

* **OIDC Authorization Code Flow**
* **Keycloak Realm configured for Canton Network users**

Future Support:

* Other OAuth/OIDC Identity Providers (Azure AD, Auth0, Ping Identity, etc.).

***

### Keycloak Configuration

Metra uses OIDC claims to determine access and the corresponding party identity of a user.

#### 3.1 Create an OIDC Client for Metra

In your Canton Keycloak realm:

1. Go to **Clients** → **Create**.
2. Select type: **OpenID Connect**.
3. Set:
   * Client ID: `metra`
   * Access Type: `confidential`
   * Standard Flow Enabled: **ON**.
4. Save the client.

#### 3.2 Configure the Callback URL

Under **Client → Settings → Valid Redirect URIs**, add:

```
https://metra.YOUR_DOMAIN/auth/callback
```

Or if running locally:

```
http://localhost:3000/auth/callback
```

#### 3.3 Add Required User Attributes

Each Keycloak user who can access Metra **must have a party identifier**:

1. Go to **Users → {User} → Attributes**.
2. Add:
   * Key: `party_id`
   * Value: `{Canton Party ID Hint}`\
     Example: `party1::issuer-xyz`

This allows Metra to know which party the user represents on Canton network.

#### 3.4 Add Attribute Mapper to Tokens

Under **Client → Mappers → Create**:

* Name: `party_id`
* Mapper Type: **User Attribute**
* User Attribute: `party_id`
* Token Claim Name: `party_id`
* Claim JSON Type: `String`
* Add to ID token: **ON**
* Add to Access token: **ON**

This ensures `party_id` flows through OIDC tokens.


---

# Agent Instructions: 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://hydrax.gitbook.io/metra-docs/onboarding/quickstart/authentication.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.
