powerful-notebook-79556
10/02/2024, 1:33 PMbrief-egg-61061
10/02/2024, 1:33 PMbrief-egg-61061
10/02/2024, 1:33 PMtoSession
request with a JWT token in Go, you can use the XSessionToken
method of the FrontendApi
in the Ory Go SDK. Here's an example: 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 }
In this example, sessionToken
is the JWT token you want to use for the request. The CheckSession
function will return the session if the token is valid, or an error if the token is invalid or expired. Please note that you need to replace ORY_PROJECT_SLUG
with your actual project slug. Source: [Ory Documentation](https://www.ory.sh/docs/kratos/sdk/go#native---check-who-the-current-http-session-belongs-to)powerful-notebook-79556
10/02/2024, 1:42 PM