<@U04UQ68083H> Is it possible in Kratos to set a t...
# ory-copilot
c
@chilly-king-10285 Is it possible in Kratos to set a trait during registration and then make it unchangeable?
c
A message from kapa.ai
No, it is not possible to set a trait during registration and then make it unchangeable in Kratos. The traits associated with an identity in Kratos can be modified by the identity owner, for example at sign up or in the profile update process. Identity traits can also be modified by users with Ory Identities (Kratos) Admin API access. However, you can keep your identities clean by denying additional properties in the identity schema. This can be done by setting
additionalProperties
to
false
in the identity schema. Here is an example of how to deny additional properties in the identity schema:
Copy code
json {     properties: {       traits: {         type: "object",         properties: {           // ...         },         additionalProperties: false,       },     },   }
For more information, you can refer to the [Kratos documentation on Identity metadata & traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata#traits) and [Customize identity schemas](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#additional-properties).
c
@chilly-king-10285 is it possible to use admin_metadata to login
c
A message from kapa.ai
No, it is not possible to use
admin_metadata
to login. The
admin_metadata
field in Ory Kratos is used to store metadata about the user which is only accessible through admin APIs. This metadata can't be updated or modified by the identity owner. For login purposes, Ory Kratos uses identifiers such as username or email and password. These are stored as traits and credentials respectively. For example, to use a username as the login identifier, you can define the following identity schema:
Copy code
json {     "$id": "<https://example.com/registration.schema.json>",     "$schema": "<http://json-schema.org/draft-07/schema#>",     "title": "Person",     "type": "object",     "properties": {       "traits": {         "type": "object",         "properties": {           "username": {             "type": "string",             "<http://ory.sh/kratos|ory.sh/kratos>": {               "credentials": {                 "password": {                   "identifier": true                 }               }             }           }         }       }     }   }
For more information, you can refer to the [Kratos documentation on Identity metadata & traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata) and [Customize identity schemas](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#username-and-password).
c
@chilly-king-10285 Is it possible to have an unchangeable trait? Specifically, I want to generate a unique username during user registration, add it to their traits, and use it as a unique identifier across our platform, including for authentication. I need this username to be generated at registration and remain unchangeable.
c
A message from kapa.ai
No, it is not possible to set a trait during registration and then make it unchangeable in Kratos. The traits associated with an identity in Kratos can be modified by the identity owner, for example at sign up or in the profile update process. Identity traits can also be modified by users with Ory Identities (Kratos) Admin API access. However, you can control the modification of traits by implementing your own logic in the application that interacts with Kratos. For example, you can generate a unique username during registration in your application, add it to the user's traits, and then not provide an option for the user to change this username in your application's user interface. For authentication, you can use this username as an identifier. Here is an example of how to define a username as an identifier in the identity schema:
Copy code
json {     "$id": "<https://example.com/registration.schema.json>",     "$schema": "<http://json-schema.org/draft-07/schema#>",     "title": "Person",     "type": "object",     "properties": {       "traits": {         "type": "object",         "properties": {           "username": {             "type": "string",             "<http://ory.sh/kratos|ory.sh/kratos>": {               "credentials": {                 "password": {                   "identifier": true                 }               }             }           }         }       }     }   }
For more information, you can refer to the [Kratos documentation on Identity metadata & traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata) and [Customize identity schemas](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#username-and-password).