melodic-oil-50942
05/04/2024, 8:57 PMchilly-king-10285
05/04/2024, 8:57 PMchilly-king-10285
05/04/2024, 8:58 PMgo 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: 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).