-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a0278d
commit 68dc98a
Showing
4 changed files
with
219 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
--- | ||
id: sending-sms | ||
title: Send SMS to your users | ||
sidebar_label: SMS delivery configuration | ||
--- | ||
|
||
```mdx-code-block | ||
import Tabs from "@theme/Tabs" | ||
import TabItem from "@theme/TabItem" | ||
import CodeBlock from "@theme/CodeBlock" | ||
``` | ||
|
||
The Ory Network comes with an HTTP based SMS delivery option, that can be configured to point to any service that supports sending | ||
SMS via HTTP API, such as Twilio, Plivo, AWS SNS, or your own microservice. | ||
|
||
## Configuration | ||
|
||
The configuration can be done via the CLI only. Follow these steps: | ||
|
||
```mdx-code-block | ||
<Tabs groupId="console-or-cli"> | ||
<TabItem value="cli" label="Ory CLI"> | ||
``` | ||
|
||
1. Download the Ory Identities config from your project and save it to a file: | ||
|
||
```shell | ||
## List all available projects | ||
ory list projects | ||
|
||
## Get config | ||
ory get identity-config {project-id} --format yaml > identity-config.yaml | ||
``` | ||
|
||
2. Add the configuration for your custom SMTP server | ||
|
||
```yaml title="config.yml" | ||
courier: | ||
channels: | ||
- id: sms | ||
type: http | ||
request_config: | ||
url: https://api.twilio.com/2010-04-01/Accounts/AXXXXXXXXXXXXXX/Messages.json # Adjust your account ID | ||
method: POST | ||
body: base64://ZnVuY3Rpb24oY3R4KSB7ClRvOiBjdHguUmVjaXBpZW50LApCb2R5OiBjdHguQm9keSwKfQ== # see below | ||
headers: | ||
Content-Type: application/x-www-form-urlencoded # defaults to application/json | ||
auth: | ||
type: basic_auth # or api_key | ||
config: | ||
user: AXXXXXXX # adjust your credentials | ||
password: XXXX # adjust your credentials | ||
``` | ||
3. Update the Ory Identities configuration using the file you worked with: | ||
```shell | ||
ory update identity-config {project-id} --file updated_config.yaml | ||
``` | ||
|
||
### Body configuration | ||
|
||
The body of the above snippet decodes to the following Jsonnet template: | ||
|
||
```jsonnet | ||
function(ctx) { | ||
To: ctx.Recipient, | ||
Body: ctx.Body, | ||
} | ||
``` | ||
|
||
All available fields on the `ctx` object are: | ||
|
||
- `Recipient`: The recipient's phone number | ||
- `Body`: The message body | ||
- `TemplateType`: The template type, e.g. `verification_code` | ||
- `TemplateData`: The template data, e.g. `{ "VerificationCode": "1234", Idenity: { ... } }` | ||
- `MessageType`: The message type, e.g. `sms` | ||
|
||
Read the [Jsonnet documentation](../../kratos/reference/jsonnet.mdx) to learn more about the Jsonnet templating language. | ||
|
||
```mdx-code-block | ||
</TabItem> | ||
</Tabs> | ||
``` | ||
|
||
## Templates | ||
|
||
Currently, only the `verification_code` template supports an SMS variant. To configure it, use the CLI: | ||
|
||
```mdx-code-block | ||
<Tabs groupId="console-or-cli"> | ||
<TabItem value="cli" label="Ory CLI"> | ||
``` | ||
|
||
1. Download the Ory Identities config from your project and save it to a file: | ||
|
||
```shell | ||
## List all available projects | ||
ory list projects | ||
|
||
## Get config | ||
ory get identity-config {project-id} --format yaml > identity-config.yaml | ||
``` | ||
|
||
2. Add the configuration for your custom SMTP server | ||
|
||
```yaml title="config.yml" | ||
courier: | ||
templates: | ||
verification_code: | ||
valid: | ||
sms: | ||
body: | ||
plaintext: "Your verification code is: {{ .VerificationCode }}" | ||
``` | ||
3. Update the Ory Identities configuration using the file you worked with: | ||
```shell | ||
ory update identity-config {project-id} --file updated_config.yaml | ||
``` | ||
|
||
```mdx-code-block | ||
</TabItem> | ||
</Tabs> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
id: mfa-via-sms | ||
title: Code via SMS | ||
sidebar_label: SMS | ||
--- | ||
|
||
```mdx-code-block | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import BrowserWindow from "@site/src/theme/BrowserWindow" | ||
``` | ||
|
||
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 | ||
Twilio, Amazon SNS or your own application. These codes are valid for a short amount of time, usually 15 minutes or less. Once the | ||
user completes the challenge, by entering the code, the AAL of the session is upgraded to AAL2. | ||
|
||
:::note | ||
|
||
Ory currently only supports either MFA via SMS or passwordless login via Code, not both. | ||
|
||
::: | ||
|
||
```mdx-code-block | ||
<BrowserWindow url="https://playground.projects.oryapis.com/ui/login?aal=aal2&via=phone"> | ||
![Recovery Codes generation in Ory Account Experience](../_static/mfa/11.png) | ||
</BrowserWindow> | ||
``` | ||
|
||
## Configuration | ||
|
||
To enable MFA via SMS, you need to configure an SMS channel in the Ory configuration: | ||
|
||
```mdx-code-block | ||
<Tabs groupId="console-or-cli"> | ||
<TabItem value="cli" label="Ory CLI" default> | ||
``` | ||
|
||
1. Get the Ory Identities configuration from your project and save it to a file: | ||
|
||
```shell | ||
## List all available projects | ||
ory list projects | ||
|
||
## Get config | ||
ory get identity-config {project-id} --format yaml > identity-config.yaml | ||
``` | ||
|
||
2. Find `code` in `selfservice.methods` and set `mfa_enabled` to `true`: | ||
|
||
```yaml title="identity-config.yaml" | ||
code: | ||
mfa_enabled: true | ||
``` | ||
3. Update the Ory Identities configuration using the file you worked with: | ||
```shell | ||
ory update identity-config {project-id} --file identity-config.yaml | ||
``` | ||
|
||
```mdx-code-block | ||
</TabItem> | ||
</Tabs> | ||
``` | ||
|
||
## Integration | ||
|
||
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 | ||
metadata to a webhook of your choice. Please read the [SMS documentation](../emails-sms/10_sending-sms.mdx). | ||
|
||
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 | ||
also need to specify which trait to use for delivering the code to the user. Make sure, this trait exists in the identity schema | ||
and set the `via` parameter to its identifier. For example, if you have a trait called `phone_number`, you'd set `via` to | ||
`phone_number`. | ||
|
||
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 | ||
identity. So make sure this trait is required in your identity schema. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters