blue-breakfast-85466
06/17/2024, 10:53 AMfunc CreateTeacherAccount(client *kratos.APIClient, email, firstName, lastName, password string, isVerified bool) (*kratos.Identity, error) {
credentials := kratos.NewIdentityWithCredentials()
credentialsWithPassword := kratos.NewIdentityWithCredentialsPassword()
pwConfigs := kratos.NewIdentityWithCredentialsPasswordConfig()
pwConfigs.SetPassword(password)
credentialsWithPassword.SetConfig(*pwConfigs)
credentialsWithPassword.Config.SetPassword(password)
credentials.SetPassword(*credentialsWithPassword)
verifiedAddress := kratos.NewVerifiableIdentityAddress("completed", email, isVerified, "email")
stateValue, err := kratos.NewIdentityStateFromValue(string(kratos.IDENTITYSTATE_ACTIVE))
if err != nil {
return nil, err
}
traits := NewTeacherTraits(email, firstName, lastName)
traitsAsMap, err := StructToMap(traits)
if err != nil {
return nil, err
}
identityBody := kratos.CreateIdentityBody{
Credentials: credentials,
RecoveryAddresses: nil,
SchemaId: integrationTestSchemaIdTeacher,
State: stateValue,
Traits: traitsAsMap,
VerifiableAddresses: []kratos.VerifiableIdentityAddress{*verifiedAddress},
}
request := client.IdentityAPI.CreateIdentity(context.Background())
identity, _, err := request.CreateIdentityBody(identityBody).Execute()
return identity, err
}
But since version 1.0.0 NewIdentityStateFromValue and IDENTITYSTATE_ACTIVE are not supported anymore. That’s the part that is not documented in changelog’s breaking changes section. My question is: is there a substitute function I can use to set and validate the state of a to be created identity?chilly-king-10285
06/17/2024, 10:53 AMchilly-king-10285
06/17/2024, 10:54 AMPatchIdentity
method from the Ory Kratos Go SDK. Here is the example code: go package identity import ( "context" "fmt" "os" client "<http://github.com/ory/client-go|github.com/ory/client-go>" ) var authed = context.WithValue(context.Background(), client.ContextAccessToken, os.Getenv("ORY_API_KEY")) func init() { cfg := client.NewConfiguration() cfg.Servers = client.ServerConfigurations{ {URL: fmt.Sprintf("<https://%s.projects.oryapis.com>", os.Getenv("ORY_PROJECT_SLUG"))}, } ory = client.NewAPIClient(cfg) } func setState(identityId string, state string) (err error) { _, _, err = ory.IdentityApi. PatchIdentity(authed, identityId). JsonPatch([]client.JsonPatch{{Op: "replace", Path: "/state", Value: state}}).Execute() return err }
In this example, the setState
function is used to set the state of an identity. The PatchIdentity
method is used with a JSON patch operation to replace the /state
path with a new value. However, this example is for updating the state of an existing identity, not for setting the state of a new identity. The knowledge sources do not provide information on how to set the state of a new identity in the latest version of the Ory Kratos Go SDK. For more detailed and specific information, you may want to refer to the [Ory Kratos Go SDK documentation](https://www.ory.sh/docs/kratos/sdk/go) or the [Ory Kratos API reference](https://www.ory.sh/docs/kratos/reference/api).