Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions docs/identities/session-to-jwt-cors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ session:
whoami:
tokenizer:
templates:
jwt_template_1:
jwks_url: base64://... # A JSON Web Key Set (required)
claims_mapper_url: base64://... # A JsonNet template for modifying the claims
ttl: 1m # 1 minute (defaults to 10 minutes)
subject_source: id # (optional, defaults to id, other option: external_id if you're using `external_id` on identities)
another_jwt_template:
jwks_url: base64://... # A JSON Web Key Set
jwt_template_1:
jwks_url: base64://... # A JSON Web Key Set (required)
claims_mapper_url: base64://... # A JsonNet template for modifying the claims
ttl: 1m # 1 minute (defaults to 10 minutes)
subject_source: id # (optional, defaults to id, other option: external_id if you're using `external_id` on identities)
another_jwt_template:
jwks_url: base64://... # A JSON Web Key Set
```

### JSON Web Token claim mapper
Expand Down Expand Up @@ -220,3 +220,17 @@ If the key set contains more than one key, the first key in the list will be use
],
}
```

### Handling `external_id` in the JWT sub claim

If your identities use `external_id`, set `subject_source` to `external_id` in the tokenizer template to populate the JWT sub
claim with that value.

Tokenization will fail if `subject_source` is set to `external_id` but an identity is missing `external_id`. This is a security
measure that prevents issuing tokens with the same sub claim for different identities, since identity IDs and `external_id` values
are only guaranteed to be unique within their own namespaces, not across both.

To avoid this, configure a webhook to automatically set `external_id` for new identities (for example using the same ID generation
logic as your previous system).

After migration, you can switch to using Ory identity IDs and set `subject_source` back to `id`.
18 changes: 10 additions & 8 deletions docs/kratos/manage-identities/60_external-id.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ create or update identities.

Do not add `external_id` to your identity schema definition. It is handled separately by Ory Kratos internally.

### Use `external_id` in JWT `sub` claim
### Use `external_id` in tokenized session JWTs `sub` claim

Set the `subject_source` to `external_id` in the tokenization config:

Expand All @@ -43,15 +43,17 @@ session:
whoami:
tokenizer:
templates:
jwt_template_1:
jwks_url: base64://... # A JSON Web Key Set (required)
claims_mapper_url: base64://... # A JsonNet template for modifying the claims
ttl: 1m # 1 minute (defaults to 10 minutes)
subject_source: external_id
another_jwt_template:
jwks_url: base64://... # A JSON Web Key Set
jwt_template_1:
jwks_url: base64://... # A JSON Web Key Set (required)
claims_mapper_url: base64://... # A JsonNet template for modifying the claims
ttl: 1m # 1 minute (defaults to 10 minutes)
subject_source: external_id
another_jwt_template:
jwks_url: base64://... # A JSON Web Key Set
```

Read more about [session tokenization here](../../identities/session-to-jwt-cors.mdx).

This will populate the `sub` claim in JWTs with the value of `external_id`.

If `external_id` is not set for a user when `subject_source` is `external_id`, tokenization will fail.
Expand Down
Loading