future-ambulance-87414
05/03/2025, 11:23 PMbrief-egg-61061
05/03/2025, 11:23 PMbrief-egg-61061
05/03/2025, 11:24 PMtokenize_as
parameter when calling the /sessions/whoami
endpoint curl -X GET \ -H "Cookie: ory_session...=..." \ "https://$<http://PROJECT_SLUG.projects.oryapis.com/sessions/whoami?tokenize_as=jwt_example_template1|PROJECT_SLUG.projects.oryapis.com/sessions/whoami?tokenize_as=jwt_example_template1>" { // ... "tokenized": "{the-jwt}" }
You can also use the Ory SDK: javascript 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 toSessionWithJwt(sessionId: string) { const session = await frontend.toSession({ tokenize_as: "jwt_example_template1", }) const jwt = session.tokenized return jwt }
[Session to JWT documentation](https://www.ory.sh/docs/identities/session-to-jwt-cors) ### 2. Using Ory Proxy Ory Proxy can automatically translate Ory Session Cookies to JWTs. When a user makes a request with a valid Ory Session Cookie, Ory Proxy: 1. Resolves the session 2. Converts it to a JWT 3. Includes the JWT in the Authorization
HTTP header of the request to your application The JWT contains all session and identity information from the original session cookie. [Ory Proxy with JWT documentation](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel#use-ory-proxy-with-json-web-tokens) ### 3. Using Ory Oathkeeper For more advanced setups, you can use Ory Oathkeeper as an API Gateway to convert sessions to JWTs. This is mentioned as an alternative approach in the documentation. [Session Management Overview](https://www.ory.sh/docs/kratos/session-management/overview#use-ory-oathkeeper-to-convert-sessions-to-jwts) ## Why Use JWTs? While Ory sessions are not issued as JWTs by default (due to challenges with session revocation and updates), converting to JWTs can be useful for: - Making cross-origin (CORS) requests where including cookies is difficult - Representing a signed-in user with a JWT - Integrating with third-party services - Reducing API calls to Ory's endpoints Remember that Ory Network employs session caching to reduce latency for session verification, so performance concerns with direct session validation are often already addressed.future-ambulance-87414
05/03/2025, 11:24 PMsession:
whoami:
tokenizer:
templates:
zendesk:
claims_mapper_url: ...
jwks_url: file:///etc/config/jwks/zendesk.jwks.json
ttl: 10m
I can then generate the JWT with:
curl --silent -H 'Cookie: ory_session=...' <https://kratos.test/sessions/whoami?tokenize_as=zendesk>
Then the content is perfect, but the signature is never valid (I'm using Zendesk, jwt.io and https://github.com/golang-jwt/jwt/tree/main/cmd/jwt
`zendesk.jwks.json`:
{
"keys": [
{
"use": "sig",
"kty": "oct",
"kid": "c361940f-61de-4fb1-b36b-3abfd1348c67",
"alg": "HS256",
"k": "SECRET"
}
]
}
I tried using oathkeeper credentials generate --alg HS256
, or using this as a template for the Zendesk provided secret, to no avail.