<@U04UQ68083H> ory kratos, i am setting 2FA sms ``...
# ory-copilot
s
@chilly-king-10285 ory kratos, i am setting 2FA sms
Copy code
{
  "$id": "kratos/email-password/identity.schema.json",
  "$schema": "<http://json-schema.org/draft-07/schema#>",
  "title": "Person",
  "type": "object",
  "properties": {
    "traits": {
      "type": "object",
      "properties": {
        "email": {
          "type": "string",
          "format": "email",
          "title": "E-Mail",
          "minLength": 3,
          "<http://ory.sh/kratos|ory.sh/kratos>": {
            "credentials": {
              "password": {
                "identifier": false
              },
              "code": {
                "identifier": true,
                "via": "email"
              }
            },
            "verification": {
              "via": "email"
            },
            "recovery": {
              "via": "email"
            }
          }
        },
        "username": {
          "type": "string",
          "format": "username",
          "title": "User name",
          "minLength": 8,
          "maxLength": 50,
          "pattern": "^[a-zA-Z0-9][a-zA-Z0-9@_.-]{7,49}$",
          "<http://ory.sh/kratos|ory.sh/kratos>": {
            "credentials": {
              "password": {
                "identifier": true
              },
              "totp": {
                "account_name": true
              }
            }
          }
        },
        "phone": {
          "type": "string",
          "format": "tel",
          "title": "Phone number",
          "<http://ory.sh/kratos|ory.sh/kratos>": {
            "credentials": {
              "code": {
                "identifier": true,
                "via": "sms"
              }
            }
          }
        }
      },
      "required": [
        "username"
      ],
      "additionalProperties": false
    }
  }
}
when i sign up a new user
Copy code
curl --request POST \
  --url '<http://127.0.0.1:4455/kratos/self-service/registration?flow=e5aecd54-2f19-4752-b013-efaab451ac20>' \
  --header 'content-type: application/json' \
  --header 'cookie: {{regFlowCookie}}' \
  --cookie '{{regFlowCookie}}' \
  --data '{
  "csrf_token": "{{regFlowCsrf}}",
  "method": "password",
  "traits": {
    "username": "VNr00132",
    "phone": "+84962941111"
  },
  "password": "SupperPassword2025$"
}'
and get error
Copy code
"messages": [
          {
            "id": 4000001,
            "text": "credentials.code.via has unknown value \"sms\"",
            "type": "error",
            "context": {
              "reason": "credentials.code.via has unknown value \"sms\""
            }
          }
        ],
b
A message from kapa.ai
The error message
"credentials.code.via has unknown value \"sms\""
indicates that Ory Kratos does not recognize
"sms"
as a valid value for the
via
field in the
credentials.code
section of your identity schema. This usually happens if the configuration for SMS delivery is missing or incomplete. Key points to check: 1. SMS Channel Configuration: You must configure an SMS channel in your Ory Kratos (or Ory Network) project. This is required for Kratos to know how to deliver SMS messages. Without this,
"sms"
is not a valid option for
via
and will result in the error you are seeing. Follow the steps in the [Send SMS to your users](https://www.ory.sh/docs/kratos/emails-sms/sending-sms) documentation to set up the SMS channel. This involves configuring a courier channel with the ID set to
sms
and pointing it to your SMS provider (e.g., Twilio, webhook, etc.). 2. Identity Schema: Your schema for the
phone
trait is correct for enabling SMS code delivery, but it only works if the SMS channel is configured. Here’s a minimal example for the
phone
trait:
Copy code
json    "phone": {      "type": "string",      "format": "tel",      "title": "Phone number",      "<http://ory.sh/kratos|ory.sh/kratos>": {        "credentials": {          "code": {            "identifier": true,            "via": "sms"          }        }      }    }
But again, this will only work if the SMS channel is set up in your Ory configuration. 3. Restart/Reload Configuration: After updating your configuration, make sure to reload or restart your Ory Kratos instance so that the new settings take effect. Summary: The error is not with your schema, but with the missing SMS channel configuration. Set up the SMS channel as described in the [official documentation](https://www.ory.sh/docs/kratos/emails-sms/sending-sms), and the error should be resolved. If you need to see a step-by-step example of configuring the SMS channel, refer to the [SMS delivery configuration guide](https://www.ory.sh/docs/kratos/emails-sms/sending-sms) and ensure your identity schema matches the documented examples for SMS code delivery [Custom identity schema](https://www.ory.sh/docs/kratos/passwordless/one-time-code#custom-identity-schema). If you have already configured the SMS channel and still see this error, double-check that the channel ID is exactly
sms
and that your configuration changes have been applied and loaded by Kratos.
s
@chilly-king-10285 I setup
Copy code
feature_flags:
  use_continue_with_transitions: true

session:
  lifespan: 24h
  whoami:
    required_aal: highest_available
  cookie:
    same_site: Strict

cookies:
  same_site: Strict

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://ZnVuY3Rpb24oY3R4KSB7CiAgVG86IGN0eC5yZWNpcGllbnQsCiAgQm9keTogY3R>4LmJvZHksCn0= # see below
        headers:
          Content-Type: application/x-www-form-urlencoded # required for Twilio, defaults to application/json
        auth:
          type: basic_auth # or api_key
          config:
            user: AXXXXXXX # adjust your credentials
            password: XXXX # adjust your credentials
b
A message from kapa.ai
Your configuration for the SMS courier channel appears correct and matches the documented example for integrating with Twilio using Ory Kratos. The key elements—`id: sms`,
type: http
, the correct
url
,
method
,
headers
, and `auth`—are all present, and the
body
is a base64-encoded Jsonnet template as required by Ory Kratos for SMS delivery configuration. This setup is necessary for enabling features like 2FA via SMS or passwordless login with SMS codes. Important points to ensure: - The
id
for the channel is exactly
sms
, which is required for Kratos to recognize and use it for SMS delivery. - The
body
field should decode to a Jsonnet function that returns the required fields for Twilio, as shown in the documentation:
Copy code
jsonnet   function(ctx) {     To: ctx.recipient,     Body: ctx.body,   }
- Your credentials (
user
and
password
) must be valid for your Twilio account. - After updating this configuration, you must reload or restart your Ory Kratos instance for the changes to take effect. Reference: This configuration is directly supported and documented in the official Ory Kratos documentation for [sending SMS](https://www.ory.sh/docs/kratos/emails-sms/sending-sms). If you have set up your identity schema to use
"via": "sms"
for the relevant trait (e.g.,
phone
), and you have this courier channel configured, Ory Kratos should be able to send SMS codes for verification, passwordless login, or MFA as expected. If you still encounter the error
"credentials.code.via has unknown value \"sms\""
, double-check that: - The configuration is loaded and active (restart Kratos if needed). - The channel
id
is exactly
sms
. - There are no typos or formatting issues in your configuration file. If all of the above is correct and the error persists, there may be an issue with how the configuration is being loaded or applied. In that case, reviewing logs for configuration errors or misapplied settings would be the next step. For more details, see the [official SMS delivery configuration guide](https://www.ory.sh/docs/kratos/emails-sms/sending-sms).