Skip to content

Commit 3e3c28f

Browse files
hperlclaudevinckr
authored andcommitted
docs: document oauth2_login_request in courier template data (#2669)
* docs: document oauth2_login_request in courier template data Kratos now includes a scoped oauth2_login_request object (challenge and the client's client_id, client_name, client_uri, logo_uri, metadata) in the login_code_valid, registration_code_valid, verification_code_valid, and verification_valid template data when the flow was started through an OAuth2 login challenge. Documents the Go template variable and the HTTP courier template_data field. See ory-corp/cloud#12776. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore: format --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: vinckr <vincent@ory.sh>
1 parent 5bad688 commit 3e3c28f

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

docs/kratos/emails-sms/05_custom-email-templates.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ In addition to the variables listed for each template, every template can access
265265
[Transient payload in templates](#transient-payload-in-templates)) and `RequestURL` (the URL of the flow request that triggered
266266
the email).
267267

268+
The `login_code.valid`, `registration_code.valid`, `verification_code.valid`, and `verification.valid` templates can also access
269+
`OAuth2LoginRequest` when the flow was started through an OAuth2 login challenge, for example when a user signs in to an OAuth2
270+
client. Because Ory resolves this value server-side, it can't be forged by the end user. Use it to brand messages per OAuth2
271+
client instead of the end-user-controlled transient payload:
272+
273+
| Variable | Description |
274+
| -------------------------------------- | ------------------------------------------------ |
275+
| `OAuth2LoginRequest.Challenge` | the OAuth2 login challenge that started the flow |
276+
| `OAuth2LoginRequest.Client.ClientID` | the OAuth2 client ID |
277+
| `OAuth2LoginRequest.Client.ClientName` | the human-readable name of the OAuth2 client |
278+
| `OAuth2LoginRequest.Client.ClientURI` | the URL of the OAuth2 client's homepage |
279+
| `OAuth2LoginRequest.Client.LogoURI` | the URL of the OAuth2 client's logo |
280+
| `OAuth2LoginRequest.Client.Metadata` | the metadata set on the OAuth2 client |
281+
282+
For example: `{{ if .OAuth2LoginRequest }}{{ .OAuth2LoginRequest.Client.ClientName }}{{ end }}`. The variable is unset when the
283+
flow wasn't started through an OAuth2 login challenge.
284+
268285
```mdx-code-block
269286
<Tabs groupId="email-templates">
270287
<TabItem value="recovery_code" label="Recovery (via code)" default>

docs/kratos/self-hosted/03_mail-courier-http.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,41 @@ available through a `ctx` object. `recipient` will always be the email address o
6464
- to
6565
- verification_url
6666
- identity
67+
- oauth2_login_request (optional)
6768
- verification_code_invalid
6869
- to
6970
- verification_code_valid
7071
- to
7172
- verification_code
7273
- identity
74+
- oauth2_login_request (optional)
75+
- login_code_valid
76+
- to
77+
- login_code
78+
- identity
79+
- oauth2_login_request (optional)
80+
- registration_code_valid
81+
- to
82+
- registration_code
83+
- traits
84+
- oauth2_login_request (optional)
85+
86+
The `oauth2_login_request` field is only present when the flow was started through an OAuth2 login challenge, for example when a
87+
user signs in to an OAuth2 client. Because Ory resolves it server-side, it can't be forged by the end user. Use it to brand
88+
messages per OAuth2 client:
89+
90+
```json
91+
"oauth2_login_request": {
92+
"challenge": "...",
93+
"client": {
94+
"client_id": "...",
95+
"client_name": "...",
96+
"client_uri": "...",
97+
"logo_uri": "...",
98+
"metadata": {}
99+
}
100+
}
101+
```
73102

74103
A universal Jsonnet template that works with all flows, would look like this:
75104

0 commit comments

Comments
 (0)