few-oyster-74399
06/12/2024, 9:48 AMchilly-king-10285
06/12/2024, 9:48 AMchilly-king-10285
06/12/2024, 9:48 AMfew-oyster-74399
06/12/2024, 9:49 AMchilly-king-10285
06/12/2024, 9:49 AMchilly-king-10285
06/12/2024, 9:49 AMDELETE /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: 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).few-oyster-74399
06/12/2024, 9:50 AMchilly-king-10285
06/12/2024, 9:50 AMchilly-king-10285
06/12/2024, 9:50 AMinactive
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: 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: 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).