limited-city-59768
03/12/2024, 4:06 AMchilly-king-10285
03/12/2024, 4:06 AMchilly-king-10285
03/12/2024, 4:07 AM/sessions/whoami
endpoint. This can be done using different methods such as cURL, Go, TypeScript, or using the Ory SDK. Here are some examples: cURL: bash curl 'https://{project.slug}.<http://projects.oryapis.com/sessions/whoami|projects.oryapis.com/sessions/whoami>' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer <your-session-token>'
Replace <your-session-token>
with your actual session token. Go: go package frontend import ( "context" "fmt" "os" "<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 CheckSession(ctx context.Context, sessionToken string) (session *client.Session, err error) { session, _, err = ory.FrontendApi.ToSession(ctx). XSessionToken(sessionToken). Execute() if err != nil { // error revoking the session, for example due to expired token provided return nil, err } return session, nil }
TypeScript: typescript import { Configuration, FrontendApi } from "@ory/client" const frontend = new FrontendApi( new Configuration({ basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`, }), ) export async function checkSession(sessionId: string, token: string) { return await frontend.toSession({ xSessionToken: token, }) }
If the session token is valid, the endpoint will return a session object. If the credentials are invalid or no credentials were sent, the endpoint will return a HTTP 401 status code. Sources: - [Ory Kratos Session Management Overview](https://www.ory.sh/docs/kratos/session-management/overview#using-ory-session-token) - [Ory Kratos API Reference](https://www.ory.sh/docs/kratos/reference/api) - [Ory Kratos Custom UI Basic Integration](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#session-checks)