<@U04UQ68083H> How do I lock or ban an identity fr...
# ory-copilot
f
@chilly-king-10285 How do I lock or ban an identity from fruther logins?
c
A message from kapa.ai
Hmm, I don't know enough to give you a confident answer yet. The provided knowledge sources do not contain information on how to lock or ban an identity from further logins using Ory. I recommend checking the [Ory documentation](https://www.ory.sh/docs/) for more information on this topic.
f
@chilly-king-10285 maybe I need to deactive an identity?
c
A message from kapa.ai
Based on the provided knowledge sources, there isn't a direct method to deactivate an identity. However, you can deactivate a session associated with an identity using the
DELETE /admin/sessions/{id}
endpoint. This will deactivate the specified session, but it won't delete the session data. Here's how you can do it:
Copy code
http DELETE /admin/sessions/{session_id}
Replace
{session_id}
with the ID of the session you want to deactivate. Note that you need to be authenticated to perform this operation, and one of the methods to authenticate is by using an
oryAccessToken
. Please note that deactivating a session is not the same as deactivating an identity. The user associated with the deactivated session may still be able to create a new session (i.e., log in again) unless additional measures are taken. For more details, please refer to the [Ory Kratos API documentation](https://www.ory.sh/docs/kratos/reference/api).
f
c
A message from kapa.ai
Yes, you can change the state of an identity to
inactive
to prevent it from using self-service flows such as sign-in. This can be done using the Ory SDK. Here's how you can do it in JavaScript and Go: In JavaScript:
Copy code
javascript 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}.<http://projects.oryapis.com|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)   }
In Go:
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 both examples, replace
identityId
with the ID of the identity you want to deactivate, and
state
with
"inactive"
. Please note that when an inactive identity tries to sign in, the server responds with a UI error. For more details, please refer to the [Ory Identity State documentation](https://www.ory.sh/docs/identities/model/activate-deactivate-user-login-state).