{"id":18875795,"url":"https://github.com/wiremock/wiremock-jwt-extension","last_synced_at":"2025-04-14T17:31:39.456Z","repository":{"id":231538524,"uuid":"782012116","full_name":"wiremock/wiremock-jwt-extension","owner":"wiremock","description":"Handlebars template helper for producing JWT and JWKS","archived":false,"fork":false,"pushed_at":"2024-10-28T09:53:00.000Z","size":102,"stargazers_count":7,"open_issues_count":4,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-28T12:57:15.494Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wiremock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-04T13:21:49.000Z","updated_at":"2024-10-28T09:52:58.000Z","dependencies_parsed_at":"2024-09-16T10:36:06.976Z","dependency_job_id":null,"html_url":"https://github.com/wiremock/wiremock-jwt-extension","commit_stats":null,"previous_names":["wiremock/wiremock-jwt-extension"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-jwt-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-jwt-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-jwt-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiremock%2Fwiremock-jwt-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wiremock","download_url":"https://codeload.github.com/wiremock/wiremock-jwt-extension/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223639348,"owners_count":17177816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T06:09:10.501Z","updated_at":"2024-11-08T06:09:11.095Z","avatar_url":"https://github.com/wiremock.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\n# YAML header\nrender_macros: false\n---\n\n# JWT Extension for WireMock\n\nAdds Handlebars helpers for generating JWT, claims and JWKS.\n\n## Java/JVM usage\n\n### Step 1: Add to your build file\n\nFor Maven users:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.wiremock.extensions\u003c/groupId\u003e\n    \u003cartifactId\u003ewiremock-jwt-extension\u003c/artifactId\u003e\n    \u003cversion\u003e0.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nFor Gradle users:\n\n```groovy\ndependencies {\n    implementation 'org.wiremock.extensions:wiremock-jwt-extension:0.2.0'\n}\n```\n\n### Step 2: Register the extension with your server\n\n```java\nnew WireMockServer(wireMockConfig().extensions(JwtExtensionFactory.class));\n```\n\n### Step 3: Create a JWKS endpoint\n\n```java\nwm.stubFor(\n    get(urlPathEqualTo(\"/.well-known/jwks.json\"))\n        .willReturn(okJson(\"{{jwks}}\").withTransformers(\"response-template\")));\n```\n\n### Step 4: Create a token endpoint\n\n```java\nwm.stubFor(\n    get(urlPathEqualTo(\"/oauth/token\"))\n        .willReturn(okJson(\"{{jwt}}\").withTransformers(\"response-template\")));\n```\n\n\n## Customising the JWT\n\nThe `jwt` helper has a number of parameters you can use to customise the generated token.\n\n### Expiry date\n\nYou can customise expiry term either by setting the `maxAge` parameter e.g.\n\n{% raw %}\n```handlebars\n{{{jwt maxAge='12 days'}}}\n```\n{% endraw %}\n\nor by setting an absolute expiry date e.g.\n\n{% raw %}\n```handlebars\n{{{jwt exp=(parseDate '2040-02-23T21:22:23Z')}}}\n```\n{% endraw %}\n\nYou can similarly set the `nbf` (not before) date:\n\n{% raw %}\n```handlebars\n{{{jwt nbf=(parseDate '2018-02-23T21:22:23Z')}}}\n```\n{% endraw %}\n\n### Standard claims\n\nStandard claims can be set as follows.\n\nIssuer:\n\n{% raw %}\n```handlebars\n{{{jwt iss='https://jwt-example.wiremockapi.cloud/'}}}\n```\n{% endraw %}\n\nAudience:\n\n{% raw %}\n```handlebars\n{{{jwt aud='https://jwt-target.wiremockapi.cloud/'}}}\n```\n{% endraw %}\n\nSubject:\n\n{% raw %}\n```handlebars\n{{{jwt sub='jonsmith'}}}\n```\n{% endraw %}\n\n### Custom claims\n\nYou can also set any custom claim you wish via named parameters e.g.\n\n{% raw %}\n```handlebars\n{{{jwt\n    isAdmin=true\n    quota=23\n    score=0.96\n    email='jonsmith@example.wiremockapi.cloud'\n    signupDate=(parseDate '2017-01-02T03:04:05Z')\n}}}\n```\n{% endraw %}\n\n### Signing with RS256\n\nBy setting the `alg` parameter, the token can be signed using the public/private key\nalgorithm:\n\n{% raw %}\n```handlebars\n{{{jwt alg='RS256'}}}\n```\n{% endraw %}\n\n## Retrieving keys\n\nFor clients to be able to validate JWTs, they need to be able to retrieve either\nthe shared secret or the public key, depending on the signing algorithm.\n\n### Getting all keys for your mock API\n\nThe keys used to sign tokens for a particular mock API can be retrieved via the\nsettings admin API resource. To fetch these via curl, you can do the following:\n\n```\ncurl http://localhost:8080/__admin/settings\n```\n\nThis will return a JSON document like this, from which you can retrieve the any of the\nkeys:\n\n```json\n{\n  \"settings\": {\n    \"extended\": {\n      \"jwt\": {\n        \"hs256Secret\": \"...\",\n        \"rs256PublicKeyId\": \"...\",\n        \"rs256PublicKey\": \"-----BEGIN RSA PUBLIC KEY-----\\n...\\n-----END RSA PUBLIC KEY-----\\n\",\n        \"rs256PrivateKey\": \"-----BEGIN RSA PRIVATE KEY-----\\n...\\n-----END RSA PRIVATE KEY-----\\n\"\n      }\n    }\n  }\n}\n```\n\n### The JSON Web Key Set (JWKS)\n\nWhen using `RS256` (public/private key) signing, it is common for clients to fetch\nthe public key for verification via a JSON Web Key Set (JWKS) endpoint. You serve\na JWKS from your mock API simply by adding a stub containing the following response\nbody (with templating enabled):\n\n{% raw %}\n```handlebars\n{{{jwks}}}\n```\n{% endraw %}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fwiremock-jwt-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiremock%2Fwiremock-jwt-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiremock%2Fwiremock-jwt-extension/lists"}