Skip to content

Commit 972019b

Browse files
jonas-jonasvinckr
andauthored
feat: add docs on sms sending (#1625)
* feat: add docs on sms sending * chore: u * fix: text bugs --------- Co-authored-by: Vincent Kraus <[email protected]>
1 parent c95f0ec commit 972019b

File tree

5 files changed

+280
-10
lines changed

5 files changed

+280
-10
lines changed

docs/kratos/_static/mfa/11.png

134 KB
Loading
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
id: sending-sms
3+
title: Send SMS to your users
4+
sidebar_label: SMS delivery configuration
5+
---
6+
7+
```mdx-code-block
8+
import Tabs from "@theme/Tabs"
9+
import TabItem from "@theme/TabItem"
10+
import CodeBlock from "@theme/CodeBlock"
11+
```
12+
13+
Ory Network comes with an HTTP based SMS delivery option that can be configured to point to any service that supports sending SMS
14+
via HTTP API, such as Twilio, Plivo, AWS SNS, or your own microservice.
15+
16+
## Configuration
17+
18+
SMS delivery can only be configured through the [Ory CLI](../../guides/cli/01_installation.mdx). Follow these steps:
19+
20+
```mdx-code-block
21+
<Tabs groupId="console-or-cli">
22+
<TabItem value="cli" label="Ory CLI">
23+
```
24+
25+
1. Download the [Ory Identities config](../../guides/cli/15_config-identity-service.mdx) from your project and save it to a file:
26+
27+
```shell
28+
## List all available projects
29+
ory list projects
30+
31+
## Get config
32+
ory get identity-config {project-id} --format yaml > identity-config.yaml
33+
```
34+
35+
2. Add the configuration for your custom SMTP server
36+
37+
```yaml title="config.yml"
38+
courier:
39+
channels:
40+
- id: sms
41+
type: http
42+
request_config:
43+
url: https://api.twilio.com/2010-04-01/Accounts/AXXXXXXXXXXXXXX/Messages.json # Adjust your account ID
44+
method: POST
45+
body: base64://ZnVuY3Rpb24oY3R4KSB7CiAgVG86IGN0eC5yZWNpcGllbnQsCiAgQm9keTogY3R4LmJvZHksCn0= # see below
46+
headers:
47+
Content-Type: application/x-www-form-urlencoded # defaults to application/json
48+
auth:
49+
type: basic_auth # or api_key
50+
config:
51+
user: AXXXXXXX # adjust your credentials
52+
password: XXXX # adjust your credentials
53+
```
54+
55+
3. Update the Ory Identities configuration using the file you worked with:
56+
57+
```shell
58+
ory update identity-config {project-id} --file updated_config.yaml
59+
```
60+
61+
### Body configuration
62+
63+
The body of the above snippet decodes to the following Jsonnet template:
64+
65+
```jsonnet
66+
function(ctx) {
67+
To: ctx.recipient,
68+
Body: ctx.body,
69+
}
70+
```
71+
72+
Fields available on the `ctx` object are:
73+
74+
- `recipient`: The recipient's phone number
75+
- `body`: The message body
76+
- `template_type`: The template type, e.g. `verification_code`
77+
- `template_data`: The template data, e.g. `{ "VerificationCode": "1234", Idenity: { ... } }`
78+
- `message_type`: The message type, e.g. `sms`
79+
80+
Read the [Jsonnet documentation](../../kratos/reference/jsonnet.mdx) to learn more about the Jsonnet templating language.
81+
82+
```mdx-code-block
83+
</TabItem>
84+
</Tabs>
85+
```
86+
87+
## Templates
88+
89+
Only the `verification_code` and `login_code` templates support an SMS variant. Use the CLI to configure it:
90+
91+
```mdx-code-block
92+
<Tabs groupId="console-or-cli">
93+
<TabItem value="cli" label="Ory CLI">
94+
```
95+
96+
1. Download the Ory Identities config from your project and save it to a file:
97+
98+
```shell
99+
## List all available projects
100+
ory list projects
101+
102+
## Get config
103+
ory get identity-config {project-id} --format yaml > identity-config.yaml
104+
```
105+
106+
2. Add the configuration for your custom SMTP server
107+
108+
```yaml title="config.yml"
109+
courier:
110+
templates:
111+
verification_code:
112+
valid:
113+
sms:
114+
body:
115+
plaintext: "base64://WW91ciB2ZXJpZmljYXRpb24gY29kZSBpczoge3sgLlZlcmlmaWNhdGlvbkNvZGUgfX0="
116+
login_code:
117+
valid:
118+
sms:
119+
body:
120+
plaintext: "base64://WW91ciBsb2dpbiBjb2RlIGlzOiB7eyAuTG9naW5Db2RlIH19"
121+
```
122+
123+
3. Update the Ory Identities configuration using the file you worked with:
124+
125+
```shell
126+
ory update identity-config {project-id} --file updated_config.yaml
127+
```
128+
129+
```mdx-code-block
130+
</TabItem>
131+
</Tabs>
132+
```

docs/kratos/mfa/30_sms.mdx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
id: mfa-via-sms
3+
title: Code via SMS
4+
sidebar_label: SMS
5+
---
6+
7+
```mdx-code-block
8+
import Tabs from '@theme/Tabs';
9+
import TabItem from '@theme/TabItem';
10+
import BrowserWindow from "@site/src/theme/BrowserWindow"
11+
```
12+
13+
SMS can be used to deliver one time codes to users. Ory will deliver a 6-digit code to an SMS gateway of your choice, such as
14+
Twilio, Amazon SNS or your own application. These codes are valid for a short amount of time, usually 15 minutes or less. Once the
15+
user completes the challenge, by entering the code, the AAL of the session is upgraded to AAL2.
16+
17+
:::note
18+
19+
Ory currently only supports either MFA via SMS or passwordless login via code, not both.
20+
21+
:::
22+
23+
```mdx-code-block
24+
<BrowserWindow url="https://playground.projects.oryapis.com/ui/login?aal=aal2&via=phone">
25+
26+
![Recovery Codes generation in Ory Account Experience](../_static/mfa/11.png)
27+
28+
</BrowserWindow>
29+
```
30+
31+
## Configuration
32+
33+
To enable MFA via SMS, you need to configure an SMS channel in the Ory configuration:
34+
35+
```mdx-code-block
36+
<Tabs groupId="console-or-cli">
37+
<TabItem value="cli" label="Ory CLI" default>
38+
```
39+
40+
1. Get the Ory Identities configuration from your project and save it to a file:
41+
42+
```shell
43+
## List all available projects
44+
ory list projects
45+
46+
## Get config
47+
ory get identity-config {project-id} --format yaml > identity-config.yaml
48+
```
49+
50+
2. Find `code` in `selfservice.methods` and set `mfa_enabled` to `true`:
51+
52+
```yaml title="identity-config.yaml"
53+
code:
54+
mfa_enabled: true
55+
```
56+
57+
3. Update the Ory Identities configuration using the file you worked with:
58+
59+
```shell
60+
ory update identity-config {project-id} --file identity-config.yaml
61+
```
62+
63+
```mdx-code-block
64+
</TabItem>
65+
</Tabs>
66+
```
67+
68+
## Integration
69+
70+
To be able to send codes via SMS, you need to provide a custom SMS sender. Ory simply sends the code, the phone number and other
71+
metadata to a webhook of your choice. Please read the [SMS documentation](../emails-sms/10_sending-sms.mdx).
72+
73+
To start a new MFA flow, for an already existing session, create a new login flow with the `aal` parameter set to `aal2`. You'll
74+
also need to specify which trait to use for delivering the code to the user. Make sure, this trait exists in the identity schema
75+
and set the `via` parameter to its identifier. For example, if you have a trait called `phone_number`, you'd set `via` to
76+
`phone_number`.
77+
78+
Ory will return an error in the UI, if the trait does not exist in the identity's schema or the trait is empty in the current
79+
identity. So make sure this trait is required in your identity schema.

docs/kratos/self-service/flows/verify-email-account-activation.mdx

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
id: verify-email-account-activation
3-
title: Verify email addresses associated with users accounts
4-
sidebar_label: Email address verification
3+
title: Verify addresses associated with users accounts
4+
sidebar_label: Address verification
55
---
66

7-
# Email address verification
7+
# Address verification
88

99
```mdx-code-block
1010
import CodeTabs from "@theme/Code/CodeTabs"
@@ -14,9 +14,9 @@ import TabItem from "@theme/TabItem"
1414
import RenderFlow from "@theme/Code/RenderFlow"
1515
```
1616

17-
Ory allows users to verify email addresses associated with their accounts. This is important to prove that the user has access to
18-
the address they used to create their account. If verification is enabled, Ory Identities starts the verification process
19-
automatically when users sign up. Users can also verify their addresses manually.
17+
Ory allows users to verify email addresses or phone numbers associated with their accounts. This is important to prove that the
18+
user has access to the address they used to create their account. If verification is enabled, Ory Identities starts the
19+
verification process automatically when users sign up. Users can also verify their addresses manually.
2020

2121
The verification flow is supported in both browsers and API clients and can be summarized as the following state machine:
2222

@@ -49,7 +49,8 @@ stateDiagram
4949
:::caution
5050

5151
Completing account verification doesn't guarantee that the account is used by the person who performed the verification. We
52-
recommend implementing additional security mechanisms to ensure that verified accounts aren't taken over by malicious actors.
52+
recommend implementing additional security mechanisms to ensure that verified accounts aren't taken over by malicious actors, such
53+
as [TOTP](../../mfa/15_totp.mdx) or [FIDO2/WebAuthn](../../mfa/20_webauthn-fido-yubikey.mdx).
5354

5455
:::
5556

@@ -63,6 +64,13 @@ recommend implementing additional security mechanisms to ensure that verified ac
6364
To configure account verification, go to **Authentication****Email Verification** in the
6465
[Ory Console](https://console.ory.sh/projects/current/verification).
6566

67+
:::caution
68+
69+
For SMS verification to work, you'll also need to configure a `courier_channel` with the ID set to `sms` via the CLI. See the
70+
**Ory CLI** tab for more information.
71+
72+
:::
73+
6674
```mdx-code-block
6775
</TabItem>
6876
<TabItem value="cli" label="Ory CLI">
@@ -143,7 +151,7 @@ provides when registering their account. Other fields inside the `traits` sectio
143151
+ }
144152
}
145153
}
146-
}
154+
},
147155
"additionalProperties": false
148156
}
149157
}
@@ -274,7 +282,7 @@ For more information see the [hooks configuration](../../hooks/01_configure-hook
274282
### Carry over verified status from Social Sign-In
275283

276284
Some Social Sign-In providers like Google return the verified status of the email address. To carry over the verified status from
277-
the Social Sign-In provider, return `verified_addresses` in your Social Sign-In JsonNet snippet:
285+
the Social Sign-In provider, return `verified_addresses` in your Social Sign-In Jsonnet snippet:
278286

279287
```jsonnet
280288
local claims = {
@@ -329,6 +337,57 @@ email.
329337

330338
If the verified address is not present in the identity's traits, the verified status is not carried over.
331339

340+
## Phone number verification
341+
342+
To send SMS messages, you need to have a trait in your identity schema that holds the phone number. The trait must be marked as a
343+
verifiable address via the `verification` extension. Here's an example of how to define such a trait in the identity schema:
344+
345+
```json
346+
{
347+
"$id": "https://schemas.ory.sh/presets/kratos/quickstart/phone-password/identity.schema.json",
348+
"$schema": "http://json-schema.org/draft-07/schema#",
349+
"title": "Person",
350+
"type": "object",
351+
"properties": {
352+
"traits": {
353+
"type": "object",
354+
"properties": {
355+
"email": {
356+
"type": "string",
357+
"title": "E-Mail",
358+
"format": "email",
359+
"ory.sh/kratos": {
360+
"credentials": {
361+
"password": {
362+
"identifier": true
363+
}
364+
},
365+
"verification": {
366+
"via": "email"
367+
}
368+
}
369+
},
370+
"phone": {
371+
"type": "string",
372+
"title": "Phone number",
373+
"format": "tel",
374+
"ory.sh/kratos": {
375+
// highlight-start
376+
"verification": {
377+
"via": "sms"
378+
}
379+
// highlight-end
380+
}
381+
}
382+
},
383+
"additionalProperties": false
384+
}
385+
}
386+
}
387+
```
388+
389+
Make sure to configure an SMS channel in the Ory configuration. See the [SMS documentation](../../emails-sms/10_sending-sms.mdx).
390+
332391
## Choosing the right strategy
333392

334393
Ory supports two strategies for verifying your user's addresses.

src/sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module.exports = {
160160
},
161161
{
162162
type: "category",
163-
label: "Sending emails",
163+
label: "Sending emails & SMS",
164164
items: [
165165
{
166166
type: "autogenerated",

0 commit comments

Comments
 (0)