narrow-hospital-35452
11/25/2024, 6:39 AMbrief-egg-61061
11/25/2024, 6:39 AMbrief-egg-61061
11/25/2024, 6:39 AMjson kratos_identity_schemas: [{identity_schema_id: "<REDACTED>", is_default: true}]
In this configuration, the specified schema is set as the default [Ory Network Configuration](https://github.com/ory/network/issues/54). If you want to use a non-default schema for registration, you would need to specify it when initializing the registration flow. However, the exact method for doing this isn't explicitly stated in the provided knowledge sources. It's important to note that when using custom identity schemas, you need to ensure they are properly configured to work with all the authentication methods you plan to use, such as password, TOTP, or WebAuthn [Custom Identity Schema for TOTP](https://www.ory.sh/docs/kratos/mfa/totp#custom-identity-schema). For more detailed information on customizing identity schemas, you can refer to the [Ory documentation on customizing identity schemas](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#password-login-identifier). Remember that changes to identity schemas can have significant impacts on your authentication flows, so it's important to test thoroughly after making any changes.narrow-hospital-35452
11/25/2024, 11:13 AMbrief-egg-61061
11/25/2024, 11:13 AMbrief-egg-61061
11/25/2024, 11:14 AMPUT /admin/identities/{id}
endpoint. Here's how you can do it: 1. First, you need to have the ID of the identity you want to update. 2. Then, you can make a PUT request to the endpoint with the updated identity information, including the new metadata_public
field. Here's an example of how to structure your request: json { "schema_id": "default", "traits": { // Include the existing traits here }, "metadata_public": { // Your new public metadata goes here "example_key": "example_value" } }
It's important to note that this operation replaces the entire metadata_public
object. You can't update only a single value in metadata_public
- you need to include all existing data you want to keep along with any new data [Ory Docs: Modify identities](https://www.ory.sh/docs/guides/integrate-with-ory-cloud-through-webhooks#modify-identities). Also, keep in mind that: 1. Public metadata is visible at the /session/whoami
endpoint but cannot be modified by the users themselves [Ory Docs: Identity metadata & traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata). 2. You need an API Key to call this endpoint. Make sure you're properly authenticated when making the request [Ory Docs: Identity metadata & traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata). 3. The metadata_public
field is not validated using the identity's JSON schema. You must ensure that the metadata you store is valid according to your schema [Ory Docs: Identity metadata & traits](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata). Remember to replace {id}
in the endpoint URL with the actual ID of the identity you're updating. If you prefer to use a PATCH operation instead of PUT, you can use the PATCH /admin/identities/{id}
endpoint. The request body for a PATCH operation would look like this: json [ { "op": "replace", "path": "/metadata_public", "value": { "example_key": "example_value" } } ]
This PATCH operation also replaces the entire metadata_public
object [Ory API Reference: updateIdentity](https://www.ory.sh/docs/reference/api). Always be cautious when updating identity information and ensure you have the necessary permissions to perform these operations.narrow-hospital-35452
11/25/2024, 11:15 AMbrief-egg-61061
11/25/2024, 11:16 AMbrief-egg-61061
11/25/2024, 11:16 AMmetadata_public
field using the Ory Kratos Go SDK. Here's how you can do it: go package main import ( "context" "fmt" "os" client "<http://github.com/ory/client-go|github.com/ory/client-go>" ) func main() { // Initialize the client configuration cfg := client.NewConfiguration() cfg.Servers = client.ServerConfigurations{ {URL: fmt.Sprintf("<https://%s.projects.oryapis.com>", os.Getenv("ORY_PROJECT_SLUG"))}, } // Create an instance of the API client ory := client.NewAPIClient(cfg) // Set the access token ctx := context.WithValue(context.Background(), client.ContextAccessToken, os.Getenv("ORY_API_KEY")) // Prepare the JSON patch for updating metadata_public jsonPatch := []client.JsonPatch{ { Op: "replace", Path: "/metadata_public", Value: map[string]interface{}{"example_key": "example_value"}, }, } // Replace IDENTITY_ID with the actual ID of the identity you want to update identityID := "IDENTITY_ID" // Apply the JSON patch to update the identity _, _, err := ory.IdentityApi.PatchIdentity(ctx, identityID).JsonPatch(jsonPatch).Execute() if err != nil { fmt.Printf("Error updating identity: %v\n", err) return } fmt.Println("Identity metadata_public updated successfully") }
This code snippet demonstrates how to use the Ory Go SDK to update the metadata_public
field of an identity using the PATCH operation. Here's a breakdown of what the code does: 1. It initializes the Ory client configuration with your project's URL. 2. It creates an instance of the API client. 3. It sets up the context with your API key for authentication. 4. It prepares a JSON patch operation to replace the entire metadata_public
field. 5. It calls the PatchIdentity
method of the IdentityApi
, passing the identity ID and the JSON patch. Remember to replace IDENTITY_ID
with the actual ID of the identity you want to update. Also, make sure to set the ORY_PROJECT_SLUG
and ORY_API_KEY
environment variables with your Ory project slug and API key respectively. This approach is based on the example provided in the [Ory documentation for updating identities to use a new schema](https://www.ory.sh/docs/identities/model/manage-identity-schema#update-identities-to-use-a-new-schema), which demonstrates how to use the PatchIdentity
method. Note that this operation replaces the entire metadata_public
object. If you want to update only specific fields within metadata_public
while preserving others, you'll need to first fetch the current state of the identity, modify the metadata_public
object as needed, and then send the entire updated object in the PATCH operation.