Identity state
The identity state determines whether an identity is active or not with the following states:
active
- The identity can use self-service flows such as sign-in.inactive
- The identity can't use self-service flows.
When an inactive identity tries to sign in, the server responds with a UI error.
Change identity state using the SDK
Use the SDK to activate and de-activate identities:
- JavaScript
- Go
import { Configuration, IdentityApi } from "@ory/client"
import { JsonPatchOpEnum } from "@ory/client/api"
const identity = new IdentityApi(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function setState(
identityId: string,
state: "active" | "inactive",
) {
return await identity
.patchIdentity({
id: identityId,
jsonPatch: [
{
op: JsonPatchOpEnum.Replace,
value: state,
path: "/state",
},
],
})
.then(({ data }) => data)
}
package main
import (
"context"
"fmt"
"github.com/ory/client-go"
"os"
)
var ory *client.APIClient
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
}