worried-journalist-71921
08/07/2024, 9:18 AMchilly-king-10285
08/07/2024, 9:18 AMchilly-king-10285
08/07/2024, 9:20 AMmetadata_public
and metadata_admin
fields. The metadata_public
field stores metadata about the identity which the identity itself can see. However, you should not store sensitive information in this field. The metadata_admin
field is used to store metadata about the user which is only accessible through admin APIs. Here is an example of how you can set these fields: json { identity: { traits: { email: claims.email }, metadata_public: { discord_username: claims.discord_username, }, metadata_admin: { // ... }, } }
In this example, claims
is a variable that contains the data you want to add to the identity's metadata. You can replace discord_username
and claims.discord_username
with the actual metadata you want to add. Please note that metadata is not validated by Ory Identities, so missing entries or unexpected values can cause errors. You must ensure that the metadata you store is valid according to your schema and you must keep the schema up to date to accommodate changes in the data. For more information, you can refer to the [Ory documentation on managing identity metadata](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata). Please note that this is a JSON representation. The actual implementation in Go will depend on how you structure your Go code.worried-journalist-71921
08/07/2024, 9:20 AMchilly-king-10285
08/07/2024, 9:21 AMchilly-king-10285
08/07/2024, 9:21 AMmetadata_public
and metadata_admin
fields to the CreateIdentityBody
function. Here's how you can modify your code: go func (_k_ *OryServiceImpl) CreateIdentity(_email_ string, _skipIfExisting_ bool) (*openapiclient.Identity, error) { ctx := context.Background() CreateIdentityBody := *openapiclient.NewCreateIdentityBody( "<preset://email>", map[string]interface{}{ "email": email, "metadata_public": map[string]interface{}{ "key": "value", // replace with your actual metadata }, "metadata_admin": map[string]interface{}{ "key": "value", // replace with your actual metadata }, }, ) identity, response, err := k.client.IdentityAPI.CreateIdentity(ctx).CreateIdentityBody(CreateIdentityBody).Execute() if response.StatusCode == http.StatusConflict { if !skipIfExisting { return nil, fmt.Errorf("identity %s already exists. Skipping.\nFull HTTP response: %v", email, response) } return nil, nil } if err != nil { return nil, fmt.Errorf("error calling ProjectAPI.CreateIdentity: %v\nFull HTTP response: %v", err, response) } return identity, nil }
In this example, replace "key": "value"
with the actual metadata you want to add. The metadata_public
field is visible to the identity, while the metadata_admin
field is only accessible through admin APIs. Please note that metadata is not validated by Ory Identities, so missing entries or unexpected values can cause errors. You must ensure that the metadata you store is valid according to your schema and you must keep the schema up to date to accommodate changes in the data. For more information, you can refer to the [Ory documentation on managing identity metadata](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).worried-journalist-71921
08/07/2024, 9:32 AMchilly-king-10285
08/07/2024, 9:32 AMchilly-king-10285
08/07/2024, 9:33 AMmetadata_public
and metadata_admin
fields are not allowed in the traits
section of the identity schema. In Ory, the traits
field is used for attributes of an identity that can be updated by the identity owner, such as username or email address. The metadata_public
and metadata_admin
fields are not part of the traits
and should be added at the same level as traits
. Here's how you should structure your `CreateIdentityBody`: go CreateIdentityBody := *openapiclient.NewCreateIdentityBody( "<preset://email>", map[string]interface{}{ "traits": map[string]interface{}{ "email": email, }, "metadata_public": map[string]interface{}{ "key": "value", // replace with your actual metadata }, "metadata_admin": map[string]interface{}{ "key": "value", // replace with your actual metadata }, }, )
In this example, replace "key": "value"
with the actual metadata you want to add. The metadata_public
field is visible to the identity, while the metadata_admin
field is only accessible through admin APIs. For more information, you can refer to the [Ory documentation on managing identity metadata](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).worried-journalist-71921
08/07/2024, 9:35 AMchilly-king-10285
08/07/2024, 9:35 AMchilly-king-10285
08/07/2024, 9:35 AMtraits
field for an identity. The metadata_public
and metadata_admin
fields are not part of the identity schema, but are added when creating or updating an identity using the Ory API or SDKs. However, if you want to include metadata fields in your schema for documentation or reference purposes, you can add them at the same level as traits
. Here's how you can modify your schema: json { "$id": "<https://schemas.ory.sh/presets/kratos/identity.email.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", "<http://ory.sh/kratos|ory.sh/kratos>": { "credentials": { "password": { "identifier": true }, "webauthn": { "identifier": true }, "totp": { "account_name": true }, "code": { "identifier": true, "via": "email" } }, "recovery": { "via": "email" }, "verification": { "via": "email" } }, "maxLength": 320 } }, "required": [ "email" ], "additionalProperties": false }, "metadata_public": { "description": "Store metadata about the identity which the identity itself can see when calling for example the session endpoint. Do not store sensitive information (e.g. credit score) about the identity in this field.", "type": "object" }, "metadata_admin": { "description": "Store metadata about the user which is only accessible through admin APIs such as `GET /admin/identities/<id>`.", "type": "object" } } }
Please note that this modification is for documentation or reference purposes only. The actual metadata_public
and metadata_admin
fields are not validated against the schema and can contain any valid JSON data. For more information, you can refer to the [Ory documentation on managing identity metadata](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).worried-journalist-71921
08/07/2024, 3:34 PMchilly-king-10285
08/07/2024, 3:34 PMchilly-king-10285
08/07/2024, 3:35 PMworried-journalist-71921
08/07/2024, 3:47 PMchilly-king-10285
08/07/2024, 3:47 PMchilly-king-10285
08/07/2024, 3:48 PMafter_recovery
hook to revoke_active_sessions
. This forces anyone with access to the account to re-authenticate using the new password set up in the recovery process. Here's an example of how to set this up: yaml selfservice: flows: recovery: enabled: true ui_url: <http://your.ui/recovery> after: hooks: - hook: revoke_active_sessions
In this configuration, replace <http://your.ui/recovery>
with the URL of your recovery page. Please note that this configuration does not prevent the user from connecting to a social sign-in provider after recovering their account. If you want to disable social sign-in completely, you need to remove the social sign-in providers from the Ory Kratos configuration file. For more information, you can refer to the [Ory documentation on account recovery](https://www.ory.sh/docs/kratos/self-service/flows/account-recovery-password-reset#invalidate-other-sessions) and [configuring hooks for self-service user flows](https://www.ory.sh/docs/kratos/hooks/configure-hooks).worried-journalist-71921
08/07/2024, 3:49 PMchilly-king-10285
08/07/2024, 3:49 PMchilly-king-10285
08/07/2024, 3:50 PMtsx const mapUINode = (node: UiNode, key: number) => { if (isUiNodeInputAttributes(node.attributes)) { const attrs = node.attributes as UiNodeInputAttributes const nodeType = attrs.type if (nodeType === "password") { return ( <input name={attrs.name} type={attrs.type} autoComplete={attrs.autocomplete} /> ) } } }
In this example, the mapUINode
function only renders an input field if the type of the field is "password". You can use this function to map over the nodes in the recovery flow and only render the password field. Please note that this is a simplified example and the actual implementation will depend on your specific use case and the framework you're using. For more information, you can refer to the [Ory documentation on customizing the user interface](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#get-recovery-flow).worried-journalist-71921
08/07/2024, 3:51 PMchilly-king-10285
08/07/2024, 3:51 PMchilly-king-10285
08/07/2024, 3:51 PMPUT /admin/identities/{id}
endpoint of the Ory Kratos Admin API. Here's an example of how to do this: json PUT /admin/identities/{id} { "traits": { "username": "new_username" } }
In this example, replace {id}
with the ID of the identity you want to update, and "new_username"
with the new username. Please note that the updated traits must be valid against the Identity Schema defined for its identity traits. For more information, you can refer to the [Ory documentation on updating an identity](https://www.ory.sh/docs/reference/api#operation/updateIdentity) and [managing identity metadata and traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).worried-journalist-71921
08/07/2024, 3:52 PMfunc (k *OryServiceImpl) CreateIdentity(email string, schemaId string, skipIfExisting bool) (*openapiclient.Identity, error) {
ctx := context.Background()
CreateIdentityBody := *openapiclient.NewCreateIdentityBody(
schemaId,
map[string]interface{}{
"email": email,
},
)
identity, response, err := k.client.IdentityAPI.CreateIdentity(ctx).CreateIdentityBody(CreateIdentityBody).Execute()
if response.StatusCode == 409 {
if !skipIfExisting {
return nil, fmt.Errorf("identity %s already exists. Skipping.\nFull HTTP response: %v", email, response)
}
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("error calling ProjectAPI.CreateIdentity: %v\nFull HTTP response: %v", err, response)
}
return identity, nil
}
chilly-king-10285
08/07/2024, 3:52 PMchilly-king-10285
08/07/2024, 3:53 PMUpdateIdentity
method of the Ory Kratos Admin API. Here's how you can modify your function to update an identity: go func (k *OryServiceImpl) UpdateIdentityTraits(id string, email string) (*openapiclient.Identity, error) { ctx := context.Background() UpdateIdentityBody := *openapiclient.NewUpdateIdentityBody( map[string]interface{}{ "email": email, }, ) identity, response, err := k.client.IdentityAPI.UpdateIdentity(ctx, id).UpdateIdentityBody(UpdateIdentityBody).Execute() if err != nil { return nil, fmt.Errorf("error calling IdentityAPI.UpdateIdentity: %v\nFull HTTP response: %v", err, response) } return identity, nil }
In this example, replace id
with the ID of the identity you want to update, and email
with the new email. Please note that the updated traits must be valid against the Identity Schema defined for its identity traits. For more information, you can refer to the [Ory documentation on updating an identity](https://www.ory.sh/docs/reference/api#operation/updateIdentity) and [managing identity metadata and traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).worried-journalist-71921
08/07/2024, 4:01 PMchilly-king-10285
08/07/2024, 4:01 PMchilly-king-10285
08/07/2024, 4:01 PMgo func (k *OryServiceImpl) UpdateIdentityTraits(id string, email string, username string) (*openapiclient.Identity, error) { ctx := context.Background() UpdateIdentityBody := *openapiclient.NewUpdateIdentityBody( map[string]interface{}{ "email": email, "username": username, }, ) identity, response, err := k.client.IdentityAPI.UpdateIdentity(ctx, id).UpdateIdentityBody(UpdateIdentityBody).Execute() if err != nil { return nil, fmt.Errorf("error calling IdentityAPI.UpdateIdentity: %v\nFull HTTP response: %v", err, response) } return identity, nil }
In this example, replace id
with the ID of the identity you want to update, email
with the new email, and username
with the new username. Please note that the updated traits must be valid against the Identity Schema defined for its identity traits. For more information, you can refer to the [Ory documentation on updating an identity](https://www.ory.sh/docs/reference/api#operation/updateIdentity) and [managing identity metadata and traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).worried-journalist-71921
08/08/2024, 5:07 PMchilly-king-10285
08/08/2024, 5:07 PMchilly-king-10285
08/08/2024, 5:07 PM_metadata_admin
using the Go client, you need to use the CreateIdentity
method of the Ory Kratos Admin API. The _metadata_admin
field is used to store metadata about the user which is only accessible through admin APIs. Here's an example of how to do this: go func (k *OryServiceImpl) CreateIdentityWithAdminMetadata(email string, schemaId string, adminMetadata map[string]interface{}, skipIfExisting bool) (*openapiclient.Identity, error) { ctx := context.Background() CreateIdentityBody := *openapiclient.NewCreateIdentityBody( schemaId, map[string]interface{}{ "email": email, }, ) CreateIdentityBody.SetMetadataAdmin(adminMetadata) identity, response, err := k.client.IdentityAPI.CreateIdentity(ctx).CreateIdentityBody(CreateIdentityBody).Execute() if response.StatusCode == 409 { if !skipIfExisting { return nil, fmt.Errorf("identity %s already exists. Skipping.\nFull HTTP response: %v", email, response) } return nil, nil } if err != nil { return nil, fmt.Errorf("error calling ProjectAPI.CreateIdentity: %v\nFull HTTP response: %v", err, response) } return identity, nil }
In this example, replace email
with the email of the identity you want to create, schemaId
with the ID of the JSON Schema to be used for validating the identity's traits, and adminMetadata
with the metadata you want to store. Please note that the created identity must be valid against the Identity Schema defined for its identity traits. For more information, you can refer to the [Ory documentation on creating an identity](https://www.ory.sh/docs/reference/api#operation/createIdentity) and [managing identity metadata and traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).worried-journalist-71921
08/12/2024, 10:49 AMchilly-king-10285
08/12/2024, 10:49 AMchilly-king-10285
08/12/2024, 10:49 AMconfig.yml
). Here's an example of how to set this up: yaml selfservice: flows: settings: required_aal: highest_available session: whoami: required_aal: highest_available
In this configuration, required_aal: highest_available
forces users to provide the highest authentication factor to access their account settings. For example, users without a second factor configured can access the settings after they sign in with their password. Users that have a second factor set up (such as a TOTP app) will must complete the second factor challenge to access account settings. If you want all users that configured a second factor to complete the factor before using your app, set session.whoami.required_aal
to highest_available
. For more information, you can refer to the [Ory documentation on enforcing MFA](https://www.ory.sh/docs/kratos/self-hosted/mfa#enforce-mfa).worried-journalist-71921
08/12/2024, 11:05 AMchilly-king-10285
08/12/2024, 11:05 AMchilly-king-10285
08/12/2024, 11:05 AMory update
command. This command allows you to overwrite or import a configuration from a file. Here's an example of how to use this command: bash ory update project --project <project-id> --workspace <workspace-id> --file config.json
In this command, replace <project-id>
with the ID of your project, <workspace-id>
with the ID of your workspace, and config.json
with the path to your configuration file. You can also use the ory patch
command to adjust specific keys in the configuration: bash ory patch permission-config --project <project-id> --workspace <workspace-id> --replace '/limit/max_read_depth=3'
In this command, replace <project-id>
with the ID of your project, <workspace-id>
with the ID of your workspace, and /limit/max_read_depth=3
with the key and value you want to adjust. For more information, you can refer to the [Ory documentation on configuring projects with the Ory CLI](https://www.ory.sh/docs/guides/cli/config-with-cli) and [adjusting specific keys in the configuration](https://www.ory.sh/docs/guides/cli/configure-permission-service#adjust-specific-keys).