narrow-hospital-35452
01/15/2025, 10:20 AMbrief-egg-61061
01/15/2025, 10:20 AMbrief-egg-61061
01/15/2025, 10:20 AM<http://ory.sh/kratos|ory.sh/kratos>
extension in the JSON Schema. Here's an example of how you can define a custom identity schema with email and username as identifiers: json { "$id": "<https://example.com/example.json>", "$schema": "<http://json-schema.org/draft-07/schema#>", "title": "Person", "type": "object", "properties": { "traits": { "type": "object", "properties": { "email": { "type": "string", "format": "email", "<http://ory.sh/kratos|ory.sh/kratos>": { "credentials": { "password": { "identifier": true } } } }, "username": { "type": "string", "<http://ory.sh/kratos|ory.sh/kratos>": { "credentials": { "password": { "identifier": true } } } } }, "additionalProperties": false } } }
This schema allows users to register and login using either their email or username as the identifier. For more detailed information on customizing identity schemas, you can refer to the following resources: 1. [Identity Schema Documentation](https://www.ory.sh/docs/kratos/manage-identities/identity-schema) 2. [Custom Identity Schema Example](https://www.ory.sh/docs/kratos/concepts/credentials/username-email-password#custom-identity-schema) Remember that when customizing your identity schema, you should include only the necessary information for authentication and core user profile data. Avoid storing business logic or sensitive information directly in the identity schema.narrow-hospital-35452
01/15/2025, 10:21 AMbrief-egg-61061
01/15/2025, 10:21 AMbrief-egg-61061
01/15/2025, 10:22 AMbash # Initiate a Registration Flow actionUrl=$( curl -s -X GET -H "Accept: application/json" \ "<https://playground.projects.oryapis.com/self-service/registration/api>" \ | jq -r '.ui.action' ) # Complete Registration Flow with password method curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{"traits.email": "<mailto:user@example.com|user@example.com>", "password": "password123", "method": "password"}' \ "$actionUrl" | jq
In this example, the traits (like email) are included in the JSON payload when completing the registration flow. The specific traits you need to include depend on your configured identity schema. If you have multiple identity schemas configured, Ory Kratos will use the default schema unless otherwise specified. To use a specific non-default schema, you would need to configure it server-side in your Ory Kratos setup. For more detailed information on the registration API flow, you can refer to the [Ory Kratos API documentation for registration](https://www.ory.sh/docs/kratos/self-service/flows/user-registration#api-clients). Remember, the structure of the traits in your API request should match the schema you've defined for your identities in your Ory Kratos configuration.narrow-hospital-35452
01/15/2025, 10:24 AMIf you have multiple identity schemas configured, Ory Kratos will use the default schema unless otherwise specified. To use a specific non-default schema, you would need to configure it server-side in your Ory Kratos setup.
brief-egg-61061
01/15/2025, 10:25 AMbrief-egg-61061
01/15/2025, 10:25 AMidentity
section of your configuration. 2. You can then specify which schema should be the default, and define additional schemas. Here's an example of how to configure multiple schemas: yaml identity: default_schema_id: person schemas: - id: person url: file:///path/to/person.schema.json - id: customer url: file:///path/to/customer.schema.json
In this configuration: - default_schema_id: person
sets the "person" schema as the default. - Additional schemas are defined under schemas
, each with a unique id
and a url
pointing to the schema file. To use a specific non-default schema (like "customer" in this example), you have two options: 1. For API calls: When creating an identity using the Admin API, you can specify the schema_id
in the request body: json { "schema_id": "customer", "traits": { // traits according to the customer schema } }
2. For self-service flows: You would need to implement custom logic in your application to choose the appropriate schema based on your requirements. This might involve creating different registration URLs or adding a step in your UI to select the schema type. It's important to note that changing schemas for existing identities can lead to data inconsistencies, so it's best to plan your schema strategy carefully from the start. For more detailed information on managing identity schemas, you can refer to the [Ory documentation on managing identity schemas](https://www.ory.sh/docs/identities/model/manage-identity-schema). Remember, these changes are made in your Ory Kratos configuration and potentially in your application logic, not in individual API calls for registration flows.narrow-hospital-35452
01/15/2025, 10:27 AMFor self-service flows: You would need to implement custom logic in your application to choose the appropriate schema based on your requirements. This might involve creating different registration URLs or adding a step in your UI to select the schema type.
brief-egg-61061
01/15/2025, 10:27 AMbrief-egg-61061
01/15/2025, 10:27 AM