boundless-artist-2317
06/25/2024, 5:20 PMchilly-king-10285
06/25/2024, 5:20 PMchilly-king-10285
06/25/2024, 5:20 PMbash ory create jwk some-example-set \ --alg ES256 --project {project.id} --format json-pretty \ > es256.jwks.json
[Source](https://www.ory.sh/docs/identities/session-to-jwt-cors#end-to-end-example) 2. Next, create a JsonNet template that will be used to modify the claims of the JWT: jsonnet local claims = std.extVar('claims'); local session = std.extVar('session'); { claims: { iss: claims.iss + "/additional-component", schema_id: session.identity.schema_id, session: session, } }
[Source](https://www.ory.sh/docs/identities/session-to-jwt-cors#end-to-end-example) 3. Base64-encode these files: bash JWKS_B64_ENCODED=$(cat es256.jwks.json | base64) JSONNET_B64_ENCODED=$(cat claims.jsonnet | base64)
[Source](https://www.ory.sh/docs/identities/session-to-jwt-cors#end-to-end-example) 4. Configure your Ory Network project's tokenizer templates: bash ory patch identity-config {project.id} \ --add '/session/whoami/tokenizer/templates/jwt_example_template1={"jwks_url":"base64://'$JWKS_B64_ENCODED'","claims_mapper_url":"base64://'$JSONNET_B64_ENCODED'","ttl":"10m"}' \ --format yaml
[Source](https://www.ory.sh/docs/identities/session-to-jwt-cors#end-to-end-example) 5. Finally, convert an Ory Session to a JWT. You can do this using the Ory JS SDK or REST API: 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 }
[Source](https://www.ory.sh/docs/identities/session-to-jwt-cors#end-to-end-example) Please replace {project.id}
and {project.slug}
with your actual project ID and slug. Also, replace sessionId
with the actual session ID you want to convert to a JWT.