{"id":16577787,"url":"https://github.com/philippus/baggage-jwt","last_synced_at":"2025-07-13T08:05:42.218Z","repository":{"id":27592793,"uuid":"114527455","full_name":"Philippus/baggage-jwt","owner":"Philippus","description":"🛄 JSON Web Tokens / JWT (RFC 7519) in Scala","archived":false,"fork":false,"pushed_at":"2025-07-07T05:37:54.000Z","size":394,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-07T06:36:13.776Z","etag":null,"topics":["jwt","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Philippus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2017-12-17T10:25:57.000Z","updated_at":"2025-07-07T05:37:58.000Z","dependencies_parsed_at":"2023-02-14T11:31:01.314Z","dependency_job_id":"cdba8e7b-1585-425a-abf3-16141080280a","html_url":"https://github.com/Philippus/baggage-jwt","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Philippus/baggage-jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philippus%2Fbaggage-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philippus%2Fbaggage-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philippus%2Fbaggage-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philippus%2Fbaggage-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Philippus","download_url":"https://codeload.github.com/Philippus/baggage-jwt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philippus%2Fbaggage-jwt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265108514,"owners_count":23712466,"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":["jwt","scala"],"created_at":"2024-10-11T22:12:15.262Z","updated_at":"2025-07-13T08:05:42.172Z","avatar_url":"https://github.com/Philippus.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Baggage JWT\n\n[![build](https://github.com/Philippus/baggage-jwt/workflows/build/badge.svg)](https://github.com/Philippus/baggage-jwt/actions/workflows/scala.yml?query=workflow%3Abuild+branch%3Amain)\n[![codecov](https://codecov.io/gh/Philippus/baggage-jwt/branch/main/graph/badge.svg)](https://codecov.io/gh/Philippus/baggage-jwt)\n![Current Version](https://img.shields.io/badge/version-0.3.1-brightgreen.svg?style=flat \"0.3.1\")\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg?style=flat \"BSD 3-Clause\")](LICENSE.md)\n\nBaggage JWT is an implementation of [RFC 7519](https://tools.ietf.org/html/rfc7519) in Scala that tries to follow the\nspecification closely.\n\n## Installation\nBaggage JWT is published for Scala 2.12 and 2.13. Add the following to your `build.sbt`:\n\n```\nresolvers += Resolver.bintrayRepo(\"gn0s1s\", \"releases\")\n\nlibraryDependencies += \"nl.gn0s1s\" %% \"baggage-jwt\" % \"0.3.1\"\n```\n\n## JWT\n\n## Example usage\n\n### Creating a token\nA JsonWebToken can be created through three methods:\n- `JsonWebToken(header, claims, secretKey)` with the parameters: \n  - header: JoseHeader - the header to use\n  - claims: ClaimsSet - the claims to encode in the jwt\n  - secretKey: Key - the key used to sign the jwt\n\n- `JsonWebToken(alg, claims, secretKey)`: in this case a default header will be generated for the supplied algorithm `alg`\n\n- `JsonWebToken(jwtString)`: here the jwtString is an already encoded JWT.\n\n```scala\nimport nl.gn0s1s.baggage._\nimport nl.gn0s1s.baggage.algorithm._\nimport nl.gn0s1s.baggage.claim._\nJsonWebToken(header = JoseHeader(HS256, Some(\"JWT\"), None), Set(SubjectClaim(\"1234567890\"), PublicClaim(\"name\", \"John Doe\"), PrivateClaim(\"admin\", true)), Key(\"secret\".getBytes))\n// res0: scala.util.Try[nl.gn0s1s.baggage.JsonWebToken] = Success(eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ)\n\nJsonWebToken(alg = HS256, Set(SubjectClaim(\"1234567890\"), PublicClaim(\"name\", \"John Doe\"), PrivateClaim(\"admin\", true)), Key(\"secret\".getBytes))\n// res1: scala.util.Try[nl.gn0s1s.baggage.JsonWebToken] = Success(eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ)\n\nJsonWebToken(\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ\")\n// res2: scala.util.Try[nl.gn0s1s.baggage.JsonWebToken] = Success(eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ)\n```\n### Header\nA header can be generated using `JoseHeader(alg, typ, cty)` with the parameters:\n- `alg`: algorithm header parameter to use in the jwt\n- `typ`: type header parameter, usually contains \"JWT\"\n- `cty`: content type header parameter, usually can stay empty\n\nAn extra method `JoseHeader(alg)` is available where only the `alg` parameter needs to be provided, a `typ` of \"JWT\" and\nno `cty` will be added as defaults.\n\n```scala\nJoseHeader(HS256, Some(\"JWT\"), None)\n// res3: nl.gn0s1s.baggage.JoseHeader = JoseHeader(HS256,Some(JWT),None)\nJoseHeader(NoneAlgorithm)\n// res4: nl.gn0s1s.baggage.JoseHeader = JoseHeader(none,Some(JWT),None)\n```\n### Claims\nFor the registered claim names: `iss`, `sub`, `aud`, `exp`, `nbf`, `iat`, and `jti` there are implementations available.\nBaggage JWT is strict about the allowed values inside registered claims.\n \n### Algorithms\nThe following algorithms are supported:\n- HS256\n- HS384\n- HS512\n- None\n\n### Keys\n\n### Validating a token\nTo validate a token the method `JsonWebToken.validate` can be used, it requires:\n- `jwtString`: the jwt being validated (as a string)\n- `alg`: the algorithm to validate against\n- `secretKey`: the key to validate against\n\n```scala\nval jwt = res0.get\nJsonWebToken.validate(jwt.toString, HS256, Key(\"secret\".getBytes))\n// res5: Boolean = true\n\n```\n### Processing claims\nMost likely you want to write your own claims processor, but an example of a claims processor\n(see: `ClaimsProcessor.process`) is included which requires the following parameters:\n- `claims`: the claims being processed.\n- `reqClaimNames`: the names of claims that are required to be there.\n- `expectedClaims`: the claims that are expected to match exactly, note that the `aud` claim is processed differently than the rest.\n- `clockSkew`: the clock skew to take into account for the `exp` and `nbf` claims.\n\nThe result is a `Success` containing the claims, or a `Failure` containing an appropriate exception.\n\n```scala\nval claims = jwt.decode.get._2\nClaimsProcessor.process(claims, Set(\"sub\", \"name\", \"admin\"), Set(PrivateClaim(\"admin\", true)), java.time.Duration.ZERO)\n// res6: scala.util.Try[nl.gn0s1s.baggage.claim.ClaimsSet.ClaimsSet] = Success(Set(SubjectClaim(1234567890), PublicClaim(name,John Doe), PrivateClaim(admin,true)))\nClaimsProcessor.process(claims, Set(\"sub\", \"name\", \"admin\", \"iat\"), Set(PrivateClaim(\"admin\", true)), java.time.Duration.ZERO)\n// res7: scala.util.Try[nl.gn0s1s.baggage.claim.ClaimsSet.ClaimsSet] = Failure(java.lang.IllegalArgumentException: Not all required claim names present in claims set)\n```\n## References\n - [RFC 7519](https://tools.ietf.org/html/rfc7519)\n - https://en.wikipedia.org/wiki/JSON_Web_Token\n - [jwt.io](https://jwt.io/)\n - [authentikat-jwt](https://github.com/jasongoodwin/authentikat-jwt) - Another JWT Scala implementation which inspired\n this version\n- [public claims](https://www.iana.org/assignments/jwt/jwt.xhtml)\n\n## License\nThe code is available under the [BSD 3-Clause](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilippus%2Fbaggage-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilippus%2Fbaggage-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilippus%2Fbaggage-jwt/lists"}