acoustic-shampoo-32095
11/22/2023, 11:53 AMThis does not works:
func (kc *KratosClient) UpdateAdminMetaData(ctx context.Context, signUpRequest requests.SignUpRequest, role string) (interface{}, error) {
// Construct the traits from the signUpRequest
traits := map[string]interface{}{
"email": signUpRequest.Email,
"firstname": signUpRequest.Firstname,
"lastname": signUpRequest.Lastname
}
// Convert traits to json.RawMessage
// traitsBytes, err := json.Marshal(traits)
// if err != nil {
// kc.logger.Error().Msgf("Error marshalling traits: %v", err)
// return nil, err
// }
// Set up the metadata you want to add
metadataAdmin := AdminMetadata{
Role: role,
}
<http://kc.logger.Info|kc.logger.Info>().Msgf("Metadata admin: %v", metadataAdmin)
// Create a new Identity object
identity := &ory.UpdateIdentityBody{}
<http://kc.logger.Info|kc.logger.Info>().Msgf("Identity: %v", identity)
// Set the state, schema ID, and traits
identity.SetState("active")
identity.SetSchemaId("default")
identity.SetTraits(traits)
// var traitsMap map[string]interface{}
// err = json.Unmarshal(traitsBytes, &traitsMap)
// if err != nil {
// kc.logger.Error().Msgf("Error unmarshalling traits: %v", err)
// return nil, err
// }
// identity.SetTraits(traitsMap)
// Set the admin metadata
identity.SetMetadataAdmin(metadataAdmin)
<http://kc.logger.Info|kc.logger.Info>().Msgf("Identity end: %v", identity)
// Use the Ory SDK to update the identity
updatedIdentity, res, err := kc.oryClient.IdentityAPI.UpdateIdentity(ctx, signUpRequest.IdentityId.String()).UpdateIdentityBody(*identity).Execute()
if err != nil {
kc.logger.Error().Msgf("Error updating identity metadata: %v", err)
kc.logger.Error().Msgf("Response: %v", res)
kc.logger.Error().Msgf("Updated identity: %v", updatedIdentity)
return nil, err
}
<http://kc.logger.Info|kc.logger.Info>().Msg("Admin metadata updated successfully")
return identity, nil
}
and here the logging I got:
{"level":"info","time":"2023-11-21T18:47:46+01:00","message":"Identity: &{<nil> <nil> <nil> map[] map[]}"}
{"level":"info","time":"2023-11-21T18:47:46+01:00","message":"Identity end: &{<nil> {ADMIN} <nil> default active map[email:popoip@poas.de firstname:okdas lastname:dasopk position:dalksm,] map[]}"}
{"level":"error","time":"2023-11-21T18:47:46+01:00","message":"Error updating identity metadata: undefined response type"}
{"level":"error","time":"2023-11-21T18:47:46+01:00","message":"Response: &{404 Not Found 404 HTTP/1.1 1 1 map[Content-Length:[19] Content-Type:[text/plain; charset=utf-8] Date:[Tue, 21 Nov 2023 17:47:46 GMT] X-Content-Type-Options:[nosniff]] {404 page not found\n} 19 [] false false map[] 0x1400057e400 <nil>}"}
{"level":"error","time":"2023-11-21T18:47:46+01:00","message":"Updated identity: <nil>"}
{"level":"error","time":"2023-11-21T18:47:46+01:00","message":"Error updating admin metadata: undefined response type"}
chilly-king-10285
11/22/2023, 11:53 AMchilly-king-10285
11/22/2023, 11:54 AMUpdateIdentity
method: go updatedIdentity, res, err := kc.oryClient.IdentityAPI.UpdateIdentity(ctx, signUpRequest.IdentityId.String()).UpdateIdentityBody(*identity).Execute()
According to the [Ory documentation](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata), to update the metadata of an identity, you should use the /admin/identities/{id}
endpoint. Make sure that the signUpRequest.IdentityId.String()
in your code corresponds to a valid identity ID in your system. Also, ensure that the server URL you're using is correct. In the [Ory Kratos Go SDK setup example](https://www.ory.sh/docs/kratos/self-hosted/go), the server URL is set to <http://127.0.0.1:4434>
, which is the Kratos Admin API. Make sure that your oryClient
is configured with the correct server URL. If the issue persists, it might be helpful to check the server logs or debug the server to see why it's returning a 404 error.acoustic-shampoo-32095
11/22/2023, 11:59 AMchilly-king-10285
11/22/2023, 11:59 AMchilly-king-10285
11/22/2023, 11:59 AMoryClient
with the adminAPIURL
and setting it in the KratosClient
struct. However, the 404 error you're encountering when trying to update an identity suggests that the server can't find the requested resource. This could be due to a few reasons: 1. The identity ID you're trying to update does not exist. Make sure that signUpRequest.IdentityId.String()
corresponds to a valid identity ID in your system. 2. The endpoint or method you're trying to access does not exist. According to the [Ory Kratos API reference](https://www.ory.sh/docs/reference/api), the correct endpoint to update an identity is /identities/{id}
. Make sure that the UpdateIdentity
method in the Ory SDK corresponds to this endpoint. 3. There might be an issue with the Ory server itself. Check the server logs or debug the server to see why it's returning a 404 error. If you're still encountering issues, you might want to reach out to the Ory community on [Ory Community Slack](http://slack.ory.sh/) for further assistance.acoustic-shampoo-32095
11/22/2023, 12:13 PM