<@U04UQ68083H> is it possible to get session infor...
# ory-copilot
m
@chilly-king-10285 is it possible to get session information based on session id?
c
A message from kapa.ai
Yes, it is possible to get session information based on the session ID. Ory provides APIs that allow you to retrieve session details. Here are examples in Go and TypeScript: Go:
Copy code
go package session      import (    "context"    "<http://github.com/ory/client-go|github.com/ory/client-go>"   )      type oryMiddleware struct {    ory *ory.APIClient   }      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 GetSession(ctx context.Context, sessionId string, expandOptions []string) (session *client.Session, err error) {    session, _, err = ory.IdentityApi.GetSession(ContextWithToken(ctx), sessionId).    Expand(expandOptions).    Execute()       if err != nil {    return nil, err    }       return session, err   }
TypeScript:
Copy code
typescript import { Configuration, IdentityApi } from "@ory/client"      const identity = new IdentityApi(    new Configuration({    basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`,    accessToken: `${process.env.ORY_ACCESS_TOKEN}`,    }),   )      export async function getSession(    sessionId: string,    expandOptions?: Array<"Devices" | "Identity">,   ) {    return await identity.getSession({    id: sessionId,    expand: expandOptions,    })   }
In both examples, you need to replace
${process.env.ORY_PROJECT_SLUG}
and
${process.env.ORY_ACCESS_TOKEN}
with your actual project slug and access token. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/session-management/list-revoke-get-sessions#getting-session-details).