Skip to content

Commit

Permalink
Allow to specify JWK keys as json objects in the storage config (#4498)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski authored Nov 14, 2023
1 parent 80b3b0e commit 1aee6f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import pureconfig.ConfigReader
import pureconfig.generic.semiauto.deriveReader
import pureconfig.module.cats._

import java.util
import scala.annotation.nowarn
import scala.jdk.CollectionConverters._
import scala.util.Try

/**
* Authorization config
Expand Down Expand Up @@ -55,12 +55,13 @@ object AuthorizationMethod {

@nowarn("cat=unused")
implicit val authorizationMethodConfigReader: ConfigReader[AuthorizationMethod] = {
implicit val jwkReader: ConfigReader[JWK] = ConfigReader.fromStringTry { s => Try(JWK.parse(s)) }
implicit val jwkSetReader: ConfigReader[JWKSet] = ConfigReader[NonEmptyList[JWK]].map { l =>
new JWKSet(l.toList.asJava)
implicit val jsonObjectReader: ConfigReader[util.Map[String, AnyRef]] =
ConfigReader.configObjectConfigReader.map(configObj => configObj.unwrapped())
implicit val jwkSetReader: ConfigReader[JWKSet] = ConfigReader[NonEmptyList[util.Map[String, AnyRef]]].map {
jwkKeys => new JWKSet(jwkKeys.map(key => JWK.parse(key)).toList.asJava)
}
implicit val anonymousReader = deriveReader[Anonymous.type]
implicit val verifyToken: ConfigReader[VerifyToken] = deriveReader[VerifyToken]
implicit val anonymousReader = deriveReader[Anonymous.type]
implicit val verifyToken: ConfigReader[VerifyToken] = deriveReader[VerifyToken]

deriveReader[AuthorizationMethod]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AuthorizationMethodSuite extends FunSuite {
| issuer = bbp
| subject = admin
| audiences = [dev, staging]
| keys = [ "${key1.toJSONString}", "${key2.toJSONString}"]
| keys = [ ${key1.toJSONString}, ${key2.toJSONString}]
|}
|""".stripMargin
)
Expand All @@ -60,7 +60,7 @@ class AuthorizationMethodSuite extends FunSuite {
| type = verify-token
| issuer = bbp
| subject = admin
| keys = [ "${key1.toJSONString}" ]
| keys = [ ${key1.toJSONString} ]
|}
|""".stripMargin
)
Expand All @@ -80,7 +80,7 @@ class AuthorizationMethodSuite extends FunSuite {
|authorization {
| type = verify-token
| subject = admin
| keys = [ "${key1.toJSONString}" ]
| keys = [ ${key1.toJSONString} ]
|}
|""".stripMargin
)
Expand All @@ -96,7 +96,7 @@ class AuthorizationMethodSuite extends FunSuite {
|authorization {
| type = verify-token
| issuer = bbp
| keys = [ "${key1.toJSONString}" ]
| keys = [ ${key1.toJSONString} ]
|}
|""".stripMargin
)
Expand Down

0 comments on commit 1aee6f4

Please sign in to comment.