# Authentication

ID Check requires client authentication using signed JSON Web Tokens (JWTs), compliant with the FAPI 2.0 Security Profile.

> **Preview**
>
> ID Check OIDC4IA is in preview, so it can change. For a stable integration, use [ID Check](https://docs.stoe.no/id-check.md).

## Overview

All requests to the pushed authorisation request (PAR) and token endpoints must include:

1. **Client assertion** - A signed JWT that authenticates the client
2. **Client assertion type** - Set to `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`

## Supported algorithms

ID Check supports the following signing algorithms (FAPI 2.0 compliant):

| Algorithm | Key type      | Description                               |
| --------- | ------------- | ----------------------------------------- |
| `ES256`   | EC (P-256)    | ECDSA using P-256 and SHA-256             |
| `PS256`   | RSA           | RSASSA-PSS using SHA-256                  |
| `EdDSA`   | OKP (Ed25519) | Edwards-curve Digital Signature Algorithm |

> **Warning**
>
> ID Check does NOT support `RS256` due to FAPI 2.0 requirements.

## Client assertion JWT

The client assertion authenticates the client to ID Check.

### Header

The JWT header must contain `alg` and `kid`. The `typ` claim is optional but must be `JWT` if present.

| Claim | Required | Description                                                     |
| ----- | -------- | --------------------------------------------------------------- |
| `alg` | Yes      | Algorithm (`ES256`, `PS256`, or `EdDSA`)                        |
| `kid` | Yes      | Key ID matching the client's registered JSON Web Key Set (JWKS) |
| `typ` | No       | If present, must be `JWT`                                       |

**Example header:**

```json
{
  "alg": "ES256",
  "kid": "my-signing-key-1",
  "typ": "JWT"
}
```

### Payload

The JWT payload must contain these **required claims**:

| Claim | Required | Description                       |
| ----- | -------- | --------------------------------- |
| `iss` | Yes      | Issuer - must be the `client_id`  |
| `sub` | Yes      | Subject - must be the `client_id` |
| `aud` | Yes      | Audience - ID Check base URL      |
| `exp` | Yes      | Expiration time (Unix timestamp)  |

The payload can also contain the following **optional claims**:

| Claim | Description                      |
| ----- | -------------------------------- |
| `iat` | Issued at time (Unix timestamp)  |
| `jti` | Unique JWT identifier            |
| `nbf` | Not before time (Unix timestamp) |

**Example payload:**

```json
{
  "iss": "dip_aci_your_client_id",
  "sub": "dip_aci_your_client_id",
  "aud": "https://{base-url}",
  "exp": 1759835872
}
```

> **Note**
>
> ID Check accepts the standard JWT claims `iat`, `jti`, and `nbf`, but does not require them. ID Check rejects any other claims.

## JWKS registration

The client publishes its public keys as a JWKS ([RFC 7517](https://www.rfc-editor.org/rfc/rfc7517)) at a URL. Stø registers the URL for the client, and ID Check fetches the keys from it. The JWKS must hold the signing keys of the client and an encryption key for the ID token.

### Required JWK fields

Each signing key needs these fields:

| Field | Required | Description                              |
| ----- | -------- | ---------------------------------------- |
| `kty` | Yes      | Key type (`EC`, `RSA`, or `OKP`)         |
| `alg` | Yes      | Algorithm (`ES256`, `PS256`, or `EdDSA`) |
| `use` | Yes      | Must be `sig`                            |
| `kid` | Yes      | Unique key identifier                    |

### EC key (P-256) fields

| Field | Description              |
| ----- | ------------------------ |
| `crv` | Curve name (`P-256`)     |
| `x`   | X coordinate (Base64url) |
| `y`   | Y coordinate (Base64url) |

### RSA key fields

| Field | Description          |
| ----- | -------------------- |
| `n`   | Modulus (Base64url)  |
| `e`   | Exponent (Base64url) |

### OKP key (Ed25519) fields

| Field | Description            |
| ----- | ---------------------- |
| `crv` | Curve name (`Ed25519`) |
| `x`   | Public key (Base64url) |

### Encryption key

ID Check encrypts each ID token with `RSA-OAEP-256` and `A256GCM`. It uses the RSA public key in the client's JWKS that has `use` set to `enc`. Give this key `kty` `RSA`, `use` `enc` and `alg` `RSA-OAEP-256`, and the RSA key fields above. If the JWKS has no encryption key, the PAR endpoint returns `not_found`.

## Key rotation

ID Check fetches the client's public keys from the JWKS URI registered for the client. To rotate keys:

1. Generate a new keypair
2. Add the new public key to the client's JWKS endpoint
3. Start using the new key (reference via `kid`)
4. After a transition period, remove the old key from the client's JWKS endpoint
