JWKS
Verify a JWT with the public keys an identity provider publishes as a JWK Set, and compute the thumbprint of a key. Typical uses: check tokens issued by Keycloak, Auth0, Entra ID or Okta.
jwt verify_jwksjwt verify_jwksjwt jwk_thumbprint

jwt verify_jwks <token> <jwks>


Description

    Verify a token with a JWK Set: JSON {valid, error, header, claims, kid, alg, source, cached}. An invalid token is a result with the reason in error. The prefix Bearer is accepted

Parameters

    token:   The JWT - String - required
    jwks:   The JWKS as JSON ({"keys": [...]}), one JWK, or the https address of the JWKS - String - required
admin
jwt verify_jwks "eyJhbGciOiJFUzI1NiIsImtpZCI6ImsxIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2xvZ2luLmV4YW1wbGUuY29tIiwiYXVkIjoiYXBpIiwic3ViIjoidTQyIiwiZXhwIjo0MTAyNDQ0ODAwfQ.XMdQbsQ_0nOmHyJdYxXOhpljCjV5khicokIabeDaYBnc62bL5T2qTheO3wTBxCl2YCBMUXwAx-M6-LAIziWZZw" "{\"keys\": [{\"crv\": \"P-256\", \"kid\": \"k1\", \"kty\": \"EC\", \"x\": \"MZMSHEp2Ztg5uyopM0ORZBJPb6xWebleJoIxG2wyFq4\", \"y\": \"ZUifIROzhc3ghnsDY43gLBcbhMGxL3YFkSYYuqRWBOc\", \"use\": \"sig\", \"alg\": \"ES256\"}]}"
mentdb
{"valid": true, "error": null, "header": {"alg": "ES256", "kid": "k1", "typ": "JWT"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "u42", "exp": 4102444800}, "kid": "k1", "alg": "ES256", "source": "literal", "cached": false}
Fixed result from a real call to a local test server (127.0.0.1): A JWKS read from an address (authlib test server)
admin
jwt verify_jwks "@TOK@" "http://127.0.0.1:22003/jwks_doc" "{\"issuer\": \"https://login.example.com\", \"audience\": \"api\"}"
mentdb
{"valid": true, "error": null, "header": {"alg": "RS256", "kid": "r1", "typ": "JWT"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "u42", "exp": 4102444800}, "kid": "r1", "alg": "RS256", "source": "url", "cached": false}

jwt verify_jwks <token> <jwks> <json_params>


Description

    The same with parameters: issuer, audience, subject (exact values), leeway (60 seconds of tolerance on exp and nbf), now (seconds, for tests), require_exp (true), algs (the allowed algorithms, all those listed above by default), cache_ttl_s (300), timeout_ms (the whole call), max_bytes (of the response), ca_file (PEM file of private certification authorities), insecure (true: no check of the certificate, the result then has tls_verified false), allow_http (true: allow plain http outside the local machine)

Parameters

    token:   The JWT - String - required
    jwks:   The JWKS - String - required
    json_params:   The parameters - String - required
admin
jwt verify_jwks "eyJhbGciOiJFUzI1NiIsImtpZCI6ImsxIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2xvZ2luLmV4YW1wbGUuY29tIiwiYXVkIjoiYXBpIiwic3ViIjoidTQyIiwiZXhwIjo0MTAyNDQ0ODAwfQ.XMdQbsQ_0nOmHyJdYxXOhpljCjV5khicokIabeDaYBnc62bL5T2qTheO3wTBxCl2YCBMUXwAx-M6-LAIziWZZw" "{\"keys\": [{\"crv\": \"P-256\", \"kid\": \"k1\", \"kty\": \"EC\", \"x\": \"MZMSHEp2Ztg5uyopM0ORZBJPb6xWebleJoIxG2wyFq4\", \"y\": \"ZUifIROzhc3ghnsDY43gLBcbhMGxL3YFkSYYuqRWBOc\", \"use\": \"sig\", \"alg\": \"ES256\"}]}" "{\"issuer\": \"https://login.example.com\", \"audience\": \"api\"}"
mentdb
{"valid": true, "error": null, "header": {"alg": "ES256", "kid": "k1", "typ": "JWT"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "u42", "exp": 4102444800}, "kid": "k1", "alg": "ES256", "source": "literal", "cached": false}
Another audience is refused
admin
jwt verify_jwks "eyJhbGciOiJFUzI1NiIsImtpZCI6ImsxIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2xvZ2luLmV4YW1wbGUuY29tIiwiYXVkIjoiYXBpIiwic3ViIjoidTQyIiwiZXhwIjo0MTAyNDQ0ODAwfQ.XMdQbsQ_0nOmHyJdYxXOhpljCjV5khicokIabeDaYBnc62bL5T2qTheO3wTBxCl2YCBMUXwAx-M6-LAIziWZZw" "{\"keys\": [{\"crv\": \"P-256\", \"kid\": \"k1\", \"kty\": \"EC\", \"x\": \"MZMSHEp2Ztg5uyopM0ORZBJPb6xWebleJoIxG2wyFq4\", \"y\": \"ZUifIROzhc3ghnsDY43gLBcbhMGxL3YFkSYYuqRWBOc\", \"use\": \"sig\", \"alg\": \"ES256\"}]}" "{\"audience\": \"other-app\"}"
mentdb
{"valid": false, "error": "the audience 'other-app' is not in the token (aud: api)", "header": {"alg": "ES256", "kid": "k1", "typ": "JWT"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "u42", "exp": 4102444800}, "kid": "k1", "alg": "ES256", "source": "literal", "cached": false}
An expired token
admin
jwt verify_jwks "eyJhbGciOiJFUzI1NiIsImtpZCI6ImsxIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2xvZ2luLmV4YW1wbGUuY29tIiwiYXVkIjoiYXBpIiwic3ViIjoidTQyIiwiZXhwIjoxNzAwMDAwMDAwfQ.XwuOLDgrvDBXGC5fRL7MeD70KlX5ynM8GdwsiZVlGJjbUp9Cy8biTSox-VdoaBXSTNsiRSsE-eBz_0jZw5JHtA" "{\"keys\": [{\"crv\": \"P-256\", \"kid\": \"k1\", \"kty\": \"EC\", \"x\": \"MZMSHEp2Ztg5uyopM0ORZBJPb6xWebleJoIxG2wyFq4\", \"y\": \"ZUifIROzhc3ghnsDY43gLBcbhMGxL3YFkSYYuqRWBOc\", \"use\": \"sig\", \"alg\": \"ES256\"}]}" "{\"leeway\": 0, \"now\": 1800000000}"
mentdb
{"valid": false, "error": "the token expired at 1700000000 (now 1800000000)", "header": {"alg": "ES256", "kid": "k1", "typ": "JWT"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "u42", "exp": 1700000000}, "kid": "k1", "alg": "ES256", "source": "literal", "cached": false}
alg none is refused
admin
jwt verify_jwks "eyJhbGciOiJub25lIiwia2lkIjoiazEifQ.eyJpc3MiOiAiaHR0cHM6Ly9sb2dpbi5leGFtcGxlLmNvbSIsICJhdWQiOiAiYXBpIiwgInN1YiI6ICJ1NDIiLCAiZXhwIjogNDEwMjQ0NDgwMH0." "{\"keys\": [{\"crv\": \"P-256\", \"kid\": \"k1\", \"kty\": \"EC\", \"x\": \"MZMSHEp2Ztg5uyopM0ORZBJPb6xWebleJoIxG2wyFq4\", \"y\": \"ZUifIROzhc3ghnsDY43gLBcbhMGxL3YFkSYYuqRWBOc\", \"use\": \"sig\", \"alg\": \"ES256\"}]}"
mentdb
{"valid": false, "error": "the algorithm none is refused", "header": {"alg": "none", "kid": "k1"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "u42", "exp": 4102444800}}
The classic confusion: HS256 signed with the public key
admin
jwt verify_jwks "eyJhbGciOiJIUzI1NiIsImtpZCI6ImsxIn0.eyJpc3MiOiAiaHR0cHM6Ly9sb2dpbi5leGFtcGxlLmNvbSIsICJhdWQiOiAiYXBpIiwgInN1YiI6ICJ1NDIiLCAiZXhwIjogNDEwMjQ0NDgwMH0.NBtVFYISYI2Rwpv5pjK7KUezAFqA663Zqj6jOFsC0zc" "{\"keys\": [{\"crv\": \"P-256\", \"kid\": \"k1\", \"kty\": \"EC\", \"x\": \"MZMSHEp2Ztg5uyopM0ORZBJPb6xWebleJoIxG2wyFq4\", \"y\": \"ZUifIROzhc3ghnsDY43gLBcbhMGxL3YFkSYYuqRWBOc\", \"use\": \"sig\", \"alg\": \"ES256\"}]}"
mentdb
{"valid": false, "error": "the algorithm HS256 is refused: a JWKS holds public keys", "header": {"alg": "HS256", "kid": "k1"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "u42", "exp": 4102444800}}
A modified token
admin
jwt verify_jwks "eyJhbGciOiJFUzI1NiIsImtpZCI6ImsxIiwidHlwIjoiSldUIn0.eyJpc3MiOiAiaHR0cHM6Ly9sb2dpbi5leGFtcGxlLmNvbSIsICJhdWQiOiAiYXBpIiwgInN1YiI6ICJhZG1pbiIsICJleHAiOiA0MTAyNDQ0ODAwfQ.XMdQbsQ_0nOmHyJdYxXOhpljCjV5khicokIabeDaYBnc62bL5T2qTheO3wTBxCl2YCBMUXwAx-M6-LAIziWZZw" "{\"keys\": [{\"crv\": \"P-256\", \"kid\": \"k1\", \"kty\": \"EC\", \"x\": \"MZMSHEp2Ztg5uyopM0ORZBJPb6xWebleJoIxG2wyFq4\", \"y\": \"ZUifIROzhc3ghnsDY43gLBcbhMGxL3YFkSYYuqRWBOc\", \"use\": \"sig\", \"alg\": \"ES256\"}]}"
mentdb
{"valid": false, "error": "invalid signature", "header": {"alg": "ES256", "kid": "k1", "typ": "JWT"}, "claims": {"iss": "https://login.example.com", "aud": "api", "sub": "admin", "exp": 4102444800}, "kid": "k1", "alg": "ES256", "source": "literal", "cached": false}
Used in use cases (1 recipe)

    Security engineer › Accept only the tokens of your identity provider

jwt jwk_thumbprint <jwk>


Description

    The SHA-256 thumbprint of a JWK (RFC 7638), in Base64url: a stable identifier for a key, computed only from its required members

Parameters

    jwk:   The JWK as JSON - String - required
admin
jwt jwk_thumbprint "{\"kty\": \"RSA\", \"n\": \"0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw\", \"e\": \"AQAB\", \"alg\": \"RS256\", \"kid\": \"2011-04-29\"}"
mentdb
NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs