<@U04UQ68083H> I use a self hosted Kratos as ident...
# ory-copilot
b
@chilly-king-10285 I use a self hosted Kratos as identity management provider for my Go application. I used kratos-client-go v0.13.1 and want to upgrade it now to v1.2.0 I figured out that there are breaking changes which are not documented. However, I used to have this code in v0.13.1 to create the body of an identity:
Copy code
func 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?
c
A message from kapa.ai
Based on the provided knowledge sources, there is an example of how to set the state of an identity using the
PatchIdentity
method from the Ory Kratos Go SDK. Here is the example code:
Copy 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).