Back to directory
jwt-scala avatar

jwt-scala

JWT support for Scala. Bonus extensions for Play, Play JSON, Json4s, Circe, uPickle, Spray and Argonaut. Read more below about its uses, features, and usage.

Clone repository

git clone https://github.com/jwt-scala/jwt-scala.git

675

Stars

144

Forks

15

Watchers

Apache-2.0

License

JWT Scala

Scala support for JSON Web Token (JWT). Supports Java 8+, Scala 2.12, Scala 2.13 and Scala 3 (for json libraries that support it). Dependency free. Optional helpers for Play Framework, Play JSON, Json4s Native, Json4s Jackson, Circe, uPickle and Argonaut.

Contributor's guide

Usage

Detailed documentation is on the Microsite.

JWT Scala is divided in several sub-projects each targeting a specific JSON library, check the doc from the menu of the Microsite for installation and usage instructions.

Algorithms

If you are using String key, please keep in mind that such keys need to be parsed. Rather than implementing a super complex parser, the one in JWT Scala is pretty simple and might not work for all use-cases (especially for ECDSA keys). In such case, consider using SecretKey or PrivateKey or PublicKey directly. It is way better for you. All API support all those types.

Check ECDSA samples for more infos.

Name Description
HMD5 HMAC using MD5 algorithm
HS224 HMAC using SHA-224 algorithm
HS256 HMAC using SHA-256 algorithm
HS384 HMAC using SHA-384 algorithm
HS512 HMAC using SHA-512 algorithm
RS256 RSASSA using SHA-256 algorithm
RS384 RSASSA using SHA-384 algorithm
RS512 RSASSA using SHA-512 algorithm
ES256 ECDSA using SHA-256 algorithm
ES384 ECDSA using SHA-384 algorithm
ES512 ECDSA using SHA-512 algorithm
EdDSA EdDSA signature algorithms

Security concerns

This lib doesn't want to impose anything, that's why, by default, a JWT claim is totally empty. That said, you should always add an issuedAt attribute to it, probably using claim.issuedNow. The reason is that even HTTPS isn't perfect and having always the same chunk of data transfered can be of a big help to crack it. Generating a slightly different token at each request is way better even if it adds a bit of payload to the response. If you are using a session timeout through the expiration attribute which is extended at each request, that's fine too. I can't find the article I read about that vulnerability but if someone has some resources about the topic, I would be glad to link them.

License

This software is licensed under the Apache 2 license, quoted below.

Copyright 2021 JWT-Scala Contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Releases

What's Changed

Update scala3-library, ... to 3.3.7 by @scala-steward in #738 Update upickle to 4.4.0 by @scala-steward in #740 Update sbt-scalafmt to 2.5.6 by @scala-steward in #744 Update bcpkix-jdk...

What's Changed

Update upickle to 4.3.2 by @scala-steward in #727 Update play, play-test to 3.0.9 by @scala-steward in #728

Full Changelog: v11.0.2...v11.0.3

Note that v11.0.1 failed to publish because of the migration to Central Portal. What's Changed

Update scalafmt-core to 3.9.8 by @scala-steward in #712 Update sbt-scalafmt to 2.5.5 by @scala-steward i...

What's Changed

allow underscore in sub by @pjfanning in #711 Update scalafmt-core to 3.9.7 by @scala-steward in #703

New Contributors

@pjfanning made their first contribution in #711

Full Changelo...

Only lib updates, but bumping the major version because some lib updates have compatibility concerns (ScalaJS for example). What's Changed

Update sbt-pgp to 2.3.1 by @scala-steward in #641 Update sbt...