busy-agent-70196
04/06/2025, 10:52 PMbrief-egg-61061
04/06/2025, 10:52 PMbrief-egg-61061
04/06/2025, 10:53 PMyaml selfservice: methods: code: enabled: true config: lifespan: 15m # Defines how long the code is valid for (default 1h)
2. Configure your identity schema to mark email as an identifier for code-based authentication: json { "properties": { "traits": { "type": "object", "properties": { "email": { "type": "string", "format": "email", "<http://ory.sh/kratos|ory.sh/kratos>": { "credentials": { "code": { "identifier": true, "via": "email" } } } } } } } }
3. Configure the login flow to use the code method: yaml selfservice: flows: login: lifespan: 10m # How long the login flow is valid
4. Set up your email courier configuration to ensure emails can be sent: yaml courier: smtp: connection_uri: <smtps://username:password@smtp.example.com:587>
5. Optionally, you can customize the email templates for the OTP codes: yaml courier: template_override_path: /path/to/templates templates: login_code: valid: email: body: html: file:///path/to/template.html plaintext: file:///path/to/template.txt
These steps will enable email OTP login in your self-hosted Kratos instance. Users will receive a one-time code via email that they can use to authenticate. For more detailed information about configuring email templates and the courier service, you can refer to [Email templates in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-templates).busy-agent-70196
04/06/2025, 11:00 PMbrief-egg-61061
04/06/2025, 11:00 PMbrief-egg-61061
04/06/2025, 11:00 PMyaml selfservice: methods: code: enabled: true passwordless_enabled: true # This is important for login
2. Identity schema configuration: Ensure your identity schema properly marks the email as an identifier for code authentication: json "email": { "type": "string", "format": "email", "<http://ory.sh/kratos|ory.sh/kratos>": { "credentials": { "code": { "identifier": true, "via": "email" } } } }
3. UI integration issue: If you're using a custom UI, you might need to check if it's properly rendering the code method option. The login flow response should include the code method if properly configured. 4. Method conflicts: Based on the knowledge sources, there might be issues when multiple authentication methods are enabled. For example, if you have both password and code methods enabled, you might need to check how they interact. 5. Check for errors in logs: Look for any error messages in your Kratos logs that might indicate configuration issues. If you're still experiencing issues, you might want to check if there are any specific error messages or review your complete configuration. Some users have reported issues with method combinations as seen in [this GitHub issue](https://github.com/ory/kratos/issues/4161). For a more detailed diagnosis, you may need to share your complete configuration and any error messages you're seeing.busy-agent-70196
04/06/2025, 11:11 PMbrief-egg-61061
04/06/2025, 11:12 PMbrief-egg-61061
04/06/2025, 11:12 PMbusy-agent-70196
04/06/2025, 11:52 PMbrief-egg-61061
04/06/2025, 11:52 PMbrief-egg-61061
04/06/2025, 11:52 PMyaml courier: smtp: connection_uri: <smtps://YOUR_SES_SMTP_USERNAME:YOUR_SES_SMTP_PASSWORD@email-smtp.YOUR_REGION.amazonaws.com:465> from_address: <mailto:your-verified-email@yourdomain.com|your-verified-email@yourdomain.com> from_name: "Your Application Name" headers: X-SES-SOURCE-ARN: arn:aws:ses:YOUR_REGION:YOUR_ACCOUNT_ID:identity/yourdomain.com X-SES-FROM-ARN: arn:aws:ses:YOUR_REGION:YOUR_ACCOUNT_ID:identity/yourdomain.com X-SES-RETURN-PATH-ARN: arn:aws:ses:YOUR_REGION:YOUR_ACCOUNT_ID:identity/yourdomain.com
The custom headers are important for cross-account sending if you're using that feature with AWS SES, as mentioned in the [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted) documentation. ### 3. Configure the courier service Make sure your courier service is properly configured: yaml courier: message_retries: 5 # Number of retry attempts for failed email delivery
### 4. Run the courier worker For a single-instance setup, run Kratos with the courier watch flag: kratos serve --watch-courier
For multi-instance deployments, run the courier as a separate singleton job: kratos courier watch
### 5. Test your configuration You can test your email delivery by initiating a login flow that requires an OTP code. Check your AWS SES console to verify emails are being sent and monitor the Kratos logs for any SMTP-related errors. If you encounter deliverability issues, check the [Email deliverability issues on Ory Cloud](https://github.com/ory/network/issues/254) discussion for common troubleshooting steps, even though it's about Ory Cloud, many of the same principles apply to self-hosted deployments. Remember that AWS SES might have sending limits if you're in the sandbox environment, so you may need to request production access if you plan to send a large volume of emails. For more detailed information about mail courier configuration in self-hosted Kratos, refer to the [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted) documentation.busy-agent-70196
04/06/2025, 11:53 PMbrief-egg-61061
04/06/2025, 11:53 PMbrief-egg-61061
04/06/2025, 11:54 PMyaml courier: smtp: connection_uri: <smtps://YOUR_SERVER_TOKEN:ANYTHING@smtp.postmarkapp.com:587> from_address: <mailto:your-verified-email@yourdomain.com|your-verified-email@yourdomain.com> from_name: "Your Application Name"
Note: Postmark's SMTP service uses your Server Token as the username and any value as the password. ### 3. Configure the courier service Ensure your courier service is properly configured: yaml courier: message_retries: 5 # Number of retry attempts for failed email delivery
### 4. Run the courier worker For a single-instance setup, run Kratos with the courier watch flag: kratos serve --watch-courier
For multi-instance deployments, run the courier as a separate singleton job: kratos courier watch
### 5. Test your configuration Initiate a login flow that requires an OTP code to test your email delivery. Check your Postmark dashboard to verify emails are being sent and monitor the Kratos logs for any SMTP-related errors. If you need to customize the email templates for OTP codes, you can add this to your configuration: yaml courier: template_override_path: /path/to/templates templates: login_code: valid: email: body: html: file:///path/to/template.html plaintext: file:///path/to/template.txt
For more detailed information about mail courier configuration in self-hosted Kratos, refer to the [Mail courier in self-hosted Ory Kratos](https://www.ory.sh/docs/kratos/self-hosted/mail-courier-selfhosted) documentation.