Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Switch JWT library to use ZIO-JSON instead of Spray JSON #3154

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object Dependencies {
"commons-validator" % "commons-validator" % "1.8.0" exclude ("commons-logging", "commons-logging")

// authentication
val jwtSprayJson = "com.github.jwt-scala" %% "jwt-spray-json" % "9.0.2"
val jwtSprayJson = "com.github.jwt-scala" %% "jwt-zio-json" % "10.0.0"
// jwtSprayJson -> 9.0.2 is the latest version that's compatible with spray-json; if it wasn't for spray, this would be Scala 3 compatible
val springSecurityCore =
"org.springframework.security" % "spring-security-core" % "6.2.2" exclude ("commons-logging", "commons-logging") exclude ("org.springframework", "spring-aop")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pdi.jwt.JwtAlgorithm
import pdi.jwt.JwtClaim
import pdi.jwt.JwtHeader
import pdi.jwt.JwtSprayJson
import pdi.jwt.JwtZIOJson
import spray.json.JsObject
import spray.json.JsValue
import zio.Clock
Expand Down Expand Up @@ -113,7 +113,7 @@
expiration = Some(exp.getEpochSecond),
jwtId = Some(UuidUtil.base64Encode(uuid)),
).toJson
} yield Jwt(JwtSprayJson.encode(header, claim, jwtConfig.secret, algorithm), exp.getEpochSecond)
} yield Jwt(JwtZIOJson.encode(header, claim, jwtConfig.secret, algorithm), exp.getEpochSecond)

Check warning on line 116 in webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala#L116

Added line #L116 was not covered by tests

/**
* Validates a JWT, taking the invalidation cache into account. The invalidation cache holds invalidated
Expand Down Expand Up @@ -148,7 +148,7 @@
* @return the token's header and claim, or `None` if the token is invalid.
*/
private def decodeToken(token: String): Option[(JwtHeader, JwtClaim)] =
JwtSprayJson.decodeAll(token, jwtConfig.secret, Seq(JwtAlgorithm.HS256)) match {
JwtZIOJson.decodeAll(token, jwtConfig.secret, Seq(JwtAlgorithm.HS256)) match {

Check warning on line 151 in webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala#L151

Added line #L151 was not covered by tests
case Success((header: JwtHeader, claim: JwtClaim, _)) =>
val missingRequiredContent: Boolean = Set(
header.typ.isDefined,
Expand Down