Skip to content

Latest commit

 

History

History
90 lines (59 loc) · 5.99 KB

File metadata and controls

90 lines (59 loc) · 5.99 KB
description
This page provides the technical details of the Generate JWT policy

Generate JWT

Overview

You use the generate-JWT policy to generate a signed JWT with a configurable set of claims. This JWT can subsequently be forwarded to backend targets, or used in some other way.

When a signed JWT is generated, it is put in the jwt.generated attribute of the request execution context.

Functional and implementation information for the generate-JWT policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to v2 APIs and v4 HTTP proxy APIs. It cannot be applied to v4 message APIs or v4 TCP proxy APIs. {% endhint %}

{% tabs %} {% tab title="HTTP proxy API example" %} Sample policy configuration:

"policy-generate-jwt": {
    "signature":"RSA_RS256",
    "expiresIn":30,
    "expiresInUnit":"SECONDS",
    "issuer":"urn://gravitee-api-gw",
    "audiences":["graviteeam"],
    "customClaims":[],
    "id":"817c6cfa-6ae6-446e-a631-5ded215b404b",
    "content":"-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDg0MY5LcTnpM/N\nd9ohW/mls6CqF3PoVocwUpKSb324QFuSGvo5s2qzM1JkR2uNTS5lapGltF0Krc5j\nmUgKqVZUx3ie76ngvHTVrz9qNHe9znsTFndtpsaFZuNIiGT8X+eAYgqKUaoKA+3y\nNWynEmXL9ywtFtGommPO1iBwMYfbucuxBmwtklkzxCrFGftAsTJANy8T+CV61TpB\nP2LbFVngfT0uDgjfoG/KMSBUZR88YZNvEyj1mEDPvZPZD6vYUBlTMlWgAwAD+pUn\n6b/a1BsZ69mMvMzvOg9NhuwMLwGDwQ45Gh51Swnzk6a/Oamgpa/ehySfZkypJhPL\ndiutySELAgMBAAECggEBALjo/yFok9wzovfM7I0jqWKxLCS6xYsEII2OXSA0s6Mo\nzCiQJ9/twoVCYTI5zCycntyrmsBAaYavDmK9YJPkVC3HI18WoRNH7pETY4VnQlXL\nz08T24dE9WQkDC1MgkNSXocqHKFIKiOyt7PQXV3NtAzfcG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JWKk2Tp5gKogB\n-----END PRIVATE KEY-----"
}

{% endtab %} {% endtabs %}

Configuration

Phases

The phases checked below are supported by the generate-JWT policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsefalseonResponsefalse
onRequestContentfalseonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Options

The generate-JWT policy can be configured with the following options:

PropertyRequiredDescriptionTypeDefault
signaturetrueSignature used to sign the tokenAlgorithmRS256
kidfalsekey ID (kid) to include in the JWT headerstring-
idfalseJWT ID (jti) claim is a unique identifier for the JWTstringUUID
audiencesfalseJWT audience claim; can be a string or an array of stringsList of string-
issuerfalseClaim that identifies the issuer of the JWTstring-
subjectfalseClaim that identifies or makes a statement about the subject of the JWTstring-

Attributes

The generate-JWT policy can be configured with the following attributes:

Name Description
jwt.generated JWT generated by the policy

You can read the token using the Gravitee Expression Language:

{#context.attributes['jwt.generated']}

Compatibility matrix

The following is the compatibility matrix for APIM and the generate-JWT policy.

Plugin VersionSupported APIM versions
Up to 1.xAll

Errors

PhaseHTTP status codeMessage
onRequest500Unexpected error while creating and signing the token

Nested objects

To limit the processing time in the case of a nested object, the default max depth of a nested object has been set to 1000. This default value can be overridden using the environment variable gravitee_policy_jsonxml_maxdepth.

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-generate-jwt/blob/master/CHANGELOG.md" %}