<@U04UQ68083H> I know there is support for multipl...
# ory-copilot
p
@chilly-king-10285 I know there is support for multiple identity schemas baked into Kratos. In the past though the API did not allow creating IDs using different schemas. There was no way to specify which schema to use when creating identities. Has that been fixed?
c
A message from kapa.ai
Yes, the ability to specify which schema to use when creating identities has been implemented in Ory Kratos. When creating an identity, you can change the
schema_id
to reflect the schema you want to use for that identity. The trait key/values also depend on your schema. However, keep in mind that the command does not create a password or any other type of credential for the identity. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/manage-identities/create-users-identities).
p
@chilly-king-10285 How do I specify the schema using the Ory Kratos API?
c
A message from kapa.ai
To specify the schema when creating an identity using the Ory Kratos API, you need to set the
schema_id
in the request body. The
schema_id
should correspond to the identity schema you want to use for the new identity. Unfortunately, the exact API endpoint and request body format are not provided in the given knowledge sources. For detailed instructions, you should refer to the [Ory Kratos API documentation](https://www.ory.sh/docs/kratos/reference/api).
p
@chilly-king-10285 is this supported when self-hosting?
c
A message from kapa.ai
Yes, the ability to specify different identity schemas is supported when self-hosting Ory Kratos. You can accommodate different data models using JSON Schema and make the system work for you. This allows you to customize the user experience and data requirements to suit different types of users or entities, such as customers, internal support staff, or even devices like a smart fridge. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/ory-kratos-intro).
p
@chilly-king-10285 There is no filed for specifying the schema in the ory client API. Can I use the API to do this?
c
A message from kapa.ai
Yes, you can use the Ory Kratos API to specify the schema when updating an identity. You can use the
patchIdentity
API to change the identity schema and traits directly. Here is an example of how to do this using a cURL command:
Copy code
bash curl --location --request PATCH "https://$<http://ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID|ORY_SLUG.projects.oryapis.com/admin/identities/$IDENTITY_ID>" \   --header "Authorization: Bearer $ORY_API_KEY" \   --header "Content-Type: application/json" \   --data-raw '[   {    "op": "replace",    "path": "/schema_id",    "value": "{new-schema-id}"   },   {    "op": "remove",    "path": "/traits/foo"   },   {    "op": "add",    "path": "/traits/bar",    "value": "barfoo"   }   ]'
In this example, the
schema_id
is being replaced with a new schema id (
{new-schema-id}
). You can replace
{new-schema-id}
with the id of the schema you want to use. Please note that you need to replace
$ORY_SLUG
,
$IDENTITY_ID
, and
$ORY_API_KEY
with your actual Ory slug, identity id, and API key respectively. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/identities/model/manage-identity-schema#update-identities-to-use-a-new-schema).
p
@chilly-king-10285 that is not the ory client API, but raw HTTP. Can I use the API?
c
A message from kapa.ai
I'm sorry for the confusion. The knowledge sources provided do not include specific information on how to specify the schema when creating identities using the Ory Kratos client API. However, the Ory Kratos client API should provide methods to interact with identities, including creating and updating them. If the functionality exists in the HTTP API, it should also be available in the client API. For the exact method and its usage, please refer to the [Ory Kratos client API documentation](https://www.ory.sh/kratos/docs/reference/api/).
p
@chilly-king-10285 Can you specify the schema id when creating IDs using a browser flow?
c
A message from kapa.ai
The knowledge sources provided do not include specific information on how to specify the schema id when creating identities using a browser flow with Ory Kratos. However, in general, the schema id is typically specified when you initiate the registration flow, and it determines the structure of the identity data that the user will provide during the registration process. For the exact steps and parameters to use, please refer to the [Ory Kratos documentation](https://www.ory.sh/kratos/docs/self-service/flows/user-registration).
p
@chilly-king-10285 The end goal for this would be to support some users that have account recovery and some that do not. Is there another way to do this without needing to use multiple id schemas?
c
A message from kapa.ai
Yes, you can achieve this without using multiple identity schemas by leveraging the administrative account recovery feature of Ory Kratos. This feature allows you to initiate account recovery for users using the admin API endpoints, even for users that don't have a recovery address configured. Here's how you can manage this: 1. For users who should have account recovery, you can specify a recovery address in their identity traits. This will allow them to initiate the recovery flow themselves if they forget their password or lose access to their second authentication factor. 2. For users who should not have account recovery, you can simply not specify a recovery address in their identity traits. These users will not be able to initiate the recovery flow themselves. 3. If a user without a recovery address loses access to their account, you can initiate the recovery flow for them using the admin API. This will give you a recovery link which you can send to the user through a different channel. Please note that if the recovery flow initiated through the admin API expires, users without a recovery address can't start the flow again by themselves. For more details, you can refer to the [Ory documentation on administrative account recovery](https://www.ory.sh/docs/kratos/manage-identities/account-recovery).
p
@chilly-king-10285 If I use the admin interface I lose the kratos strong password checking though,
c
A message from kapa.ai
Yes, you're correct. When you use the admin interface to create or update identities, Ory Kratos does not enforce the same password policies as it does during the self-service registration and password update flows. This includes checks for password strength, checks against the Have I Been Pwned database, and other password policies. If you want to enforce strong password policies when creating or updating identities through the admin interface, you would need to implement these checks in your own code. For example, you could use a library to check password strength, and you could use the Have I Been Pwned API to check if a password has been compromised. For more details on Ory Kratos's password policies, you can refer to the [Ory documentation on password policies](https://www.ory.sh/docs/concepts/password-policy#best-practices).