Skip to content

Commit

Permalink
Merge pull request #12624 from mkurz/fix-jjwt-compatibility
Browse files Browse the repository at this point in the history
[3.0.x] Fix jjwt compatibility to allow upgrades
  • Loading branch information
mkurz committed May 8, 2024
2 parents dd4a674 + dc14f80 commit 8d9ba21
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/play/src/main/scala/play/api/mvc/Cookie.scala
Expand Up @@ -794,8 +794,23 @@ object JWTCookieDataCodec {
builder.setExpiration(expirationDate)
}

builder.setNotBefore(now) // https://tools.ietf.org/html/rfc7519#section-4.1.5
builder.setIssuedAt(now) // https://tools.ietf.org/html/rfc7519#section-4.1.6
try {
builder.setNotBefore(now) // https://tools.ietf.org/html/rfc7519#section-4.1.5
} catch {
case _: NoSuchMethodError => // In case users upgrade to jjwt 0.12+
classOf[JwtBuilder]
.getDeclaredMethod("notBefore", classOf[java.util.Date])
.invoke(builder, now)
}

try {
builder.setIssuedAt(now) // https://tools.ietf.org/html/rfc7519#section-4.1.6
} catch {
case _: NoSuchMethodError => // In case users upgrade to jjwt 0.12+
classOf[JwtBuilder]
.getDeclaredMethod("issuedAt", classOf[java.util.Date])
.invoke(builder, now)
}

// Sign and compact into a string...
// Even though secretKey already knows about the algorithm we have to pass signatureAlgorithm separately as well again.
Expand Down

0 comments on commit 8d9ba21

Please sign in to comment.