Learn how to build APIs with Scala and the Play Framework, and secure them using access tokens.
Read more at Build and Secure APIs with Scala and the Play Framework
Hey everyone! We’re closing this thread for now but feel free to reopen it anytime you feel like asking a question!
hubca
December 16, 2019, 6:17pm
5
It’s a useful article but it doesn’t include how to hook up automatically retrieving a new authorisation code when the the current one expires… so kind of feels unfinished
1 Like
Thanks for providing that feedback! Let me tag the article author here @steve.hobbs so he can address that once he’s online
Hey @hubca , thanks for reading.
It doesn’t cover the scenario you describe because that’s not really the responsibility of the API. It consumes the access token but is not responsible for fetching new ones when they expire.
That would normally be the responsibility of the thing that calls the API, like a web application, SPA, etc. Building that application is out of the scope of this article.
Thanks a loot for sharing it Steve!
hubca
December 17, 2019, 11:09am
9
Thanks for the response @steve.hobbs . I guess I’m looking at this as someone who has built the API with the primary objective of securely accessing our own endpoints (in our application). I’m just currently lacking knowledge of the correct way to apply the oAuth flow in order to refresh expired tokens. It’s a really useful article of course.
1 Like
Thanks for the feedback on the article!
The dependencies in the example are very out of date, and the jwt-scala API has changed since the blog was written. I have opened a pull request to update dependencies here: https://github.com/auth0-blog/scala-api-sample/pull/1 .
mish
February 4, 2024, 7:05pm
14
I agree with @phelps-sg , and I’ve posted a new issue (since the above PR is also a bit old I think for the sbt, scala, and play version).
can you please @steve.hobbs help a bit if possible? suggest the versions that should work, and I will give it a try.
mish
February 11, 2024, 7:46pm
15
opened 05:40PM - 11 Feb 24 UTC
bug
### Checklist
- [X] I have looked into the [Readme](https://github.com/auth0/… jwks-rsa-java#readme) and [Examples](https://github.com/auth0/jwks-rsa-java/blob/master/EXAMPLES.md), and have not found a suitable solution or answer.
- [X] I have looked into the [API documentation](https://javadoc.io/doc/com.auth0/jwks-rsa/latest/index.html) and have not found a suitable solution or answer.
- [X] I have searched the [issues](https://github.com/auth0/jwks-rsa-java/issues) and have not found a suitable solution or answer.
- [X] I have searched the [Auth0 Community](https://community.auth0.com) forums and have not found a suitable solution or answer.
- [X] I agree to the terms within the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
### Description
using below
**jwks-rsa 0.22.1**, **scala 2.13.12**
```
scalaVersion := "2.13.12"
libraryDependencies ++= Seq(
"com.github.jwt-scala" %% "jwt-play" % "10.0.0",
"com.github.jwt-scala" %% "jwt-core" % "10.0.0",
"com.auth0" % "jwks-rsa" % "0.22.1"
)
```
**and play framework 3.0.1**
```
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.1")
```
when run the application, ```sbt run```
### it has exceptions like beow
>
[error] com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.14.3 requires Jackson Databind version >= 2.14.0 and < 2.15.0 - Found jackson-databind version 2.15.0
**see more details:**
<details>
[info] welcome to sbt 1.9.8 (Amazon.com Inc. Java 17.0.6)
[info] loading settings for project shimba-play-framework-build from plugins.sbt ...
[info] loading project definition from /Users/min.shi/code/shimba-play-framework/project
[info] loading settings for project root from build.sbt ...
[info] __ __
[info] \ \ ____ / /____ _ __ __
[info] \ \ / __ \ / // __ `// / / /
[info] / / / /_/ // // /_/ // /_/ /
[info] /_/ / .___//_/ \__,_/ \__, /
[info] /_/ /____/
[info]
[info] Version 3.0.1 running Java 17.0.6
[info]
[info] Play is run entirely by the community. Please consider contributing and/or donating:
[info] https://www.playframework.com/sponsors
[info]
--- (Running the application, auto-reloading is enabled) ---
[error] com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.14.3 requires Jackson Databind version >= 2.14.0 and < 2.15.0 - Found jackson-databind version 2.15.0
[error] at com.fasterxml.jackson.module.scala.JacksonModule.setupModule(JacksonModule.scala:61)
[error] at com.fasterxml.jackson.module.scala.JacksonModule.setupModule$(JacksonModule.scala:46)
[error] at com.fasterxml.jackson.module.scala.DefaultScalaModule.setupModule(DefaultScalaModule.scala:17)
[error] at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:879)
[error] at org.apache.pekko.serialization.jackson.JacksonObjectMapperProvider$.$anonfun$configureObjectMapperModules$4(JacksonObjectMapperProvider.scala:252)
[error] at org.apache.pekko.serialization.jackson.JacksonObjectMapperProvider$.$anonfun$configureObjectMapperModules$4$adapted(JacksonObjectMapperProvider.scala:251)
[error] at scala.collection.immutable.List.foreach(List.scala:333)
[error] at org.apache.pekko.serialization.jackson.JacksonObjectMapperProvider$.configureObjectMapperModules(JacksonObjectMapperProvider.scala:251)
[error] at org.apache.pekko.serialization.jackson.JacksonObjectMapperProvider$.createObjectMapper(JacksonObjectMapperProvider.scala:275)
[error] at org.apache.pekko.serialization.jackson.JacksonObjectMapperProvider.create(JacksonObjectMapperProvider.scala:369)
[error] at org.apache.pekko.serialization.jackson.JacksonObjectMapperProvider.$anonfun$getOrCreate$1(JacksonObjectMapperProvider.scala:327)
[error] at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
[error] at org.apache.pekko.serialization.jackson.JacksonObjectMapperProvider.getOrCreate(JacksonObjectMapperProvider.scala:327)
[error] at org.apache.pekko.serialization.jackson.JacksonJsonSerializer.<init>(JacksonSerializer.scala:151)
[error] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
[error] at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[error] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
[error] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
[error] at org.apache.pekko.actor.ReflectiveDynamicAccess.$anonfun$createInstanceFor$1(ReflectiveDynamicAccess.scala:50)
[error] at scala.util.Try$.apply(Try.scala:210)
[error] at org.apache.pekko.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:45)
[error] at org.apache.pekko.actor.ReflectiveDynamicAccess.$anonfun$createInstanceFor$5(ReflectiveDynamicAccess.scala:58)
[error] at scala.util.Success.flatMap(Try.scala:258)
[error] at org.apache.pekko.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:57)
[error] at org.apache.pekko.serialization.Serialization$$anonfun$serializerOf$1$$anonfun$applyOrElse$1.applyOrElse(Serialization.scala:409)
[error] at org.apache.pekko.serialization.Serialization$$anonfun$serializerOf$1$$anonfun$applyOrElse$1.applyOrElse(Serialization.scala:405)
[error] at scala.util.Failure.recoverWith(Try.scala:240)
[error] at org.apache.pekko.serialization.Serialization$$anonfun$serializerOf$1.applyOrElse(Serialization.scala:405)
[error] at org.apache.pekko.serialization.Serialization$$anonfun$serializerOf$1.applyOrElse(Serialization.scala:403)
[error] at scala.util.Failure.recoverWith(Try.scala:240)
[error] at org.apache.pekko.serialization.Serialization.serializerOf(Serialization.scala:403)
[error] at org.apache.pekko.serialization.Serialization.$anonfun$serializers$2(Serialization.scala:437)
[error] at scala.collection.Iterator$$anon$9.next(Iterator.scala:584)
[error] at scala.collection.immutable.HashMapBuilder.addAll(HashMap.scala:2406)
[error] at scala.collection.immutable.HashMap$.from(HashMap.scala:2218)
[error] at scala.collection.immutable.HashMap$.from(HashMap.scala:2194)
[error] at scala.collection.MapOps$WithFilter.map(Map.scala:381)
[error] at org.apache.pekko.serialization.Serialization.<init>(Serialization.scala:437)
[error] at org.apache.pekko.serialization.SerializationExtension$.createExtension(SerializationExtension.scala:28)
[error] at org.apache.pekko.serialization.SerializationExtension$.createExtension(SerializationExtension.scala:24)
[error] at org.apache.pekko.actor.ActorSystemImpl.registerExtension(ActorSystem.scala:1177)
[error] at org.apache.pekko.actor.ActorSystemImpl.$anonfun$loadExtensions$1(ActorSystem.scala:1220)
[error] at scala.collection.immutable.Vector.foreach(Vector.scala:2124)
[error] at org.apache.pekko.actor.ActorSystemImpl.loadExtensions$1(ActorSystem.scala:1214)
[error] at org.apache.pekko.actor.ActorSystemImpl.loadExtensions(ActorSystem.scala:1233)
[error] at org.apache.pekko.actor.ActorSystemImpl.liftedTree2$1(ActorSystem.scala:1054)
[error] at org.apache.pekko.actor.ActorSystemImpl._start$lzycompute(ActorSystem.scala:1041)
[error] at org.apache.pekko.actor.ActorSystemImpl._start(ActorSystem.scala:1040)
[error] at org.apache.pekko.actor.ActorSystemImpl.start(ActorSystem.scala:1064)
[error] at org.apache.pekko.actor.ActorSystem$.apply(ActorSystem.scala:282)
[error] at org.apache.pekko.actor.ActorSystem$.apply(ActorSystem.scala:326)
[error] at org.apache.pekko.actor.ActorSystem$.apply(ActorSystem.scala:300)
[error] at play.core.server.DevServerStart$.mkServerActorSystem(DevServerStart.scala:90)
[error] at play.core.server.DevServerStart$.$anonfun$mainDev$1(DevServerStart.scala:80)
[error] at play.core.server.DevServerStart.$anonfun$mainDev$2(DevServerStart.scala:308)
[error] at play.utils.Threads$.withContextClassLoader(Threads.scala:22)
[error] at play.core.server.DevServerStart.mainDev(DevServerStart.scala:107)
[error] at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:80)
[error] at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:55)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[error] at play.runsupport.Reloader$.startDevMode(Reloader.scala:314)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.14.3 requires Jackson Databind version >= 2.14.0 and < 2.15.0 - Found jackson-databind version 2.15.0
[error] Total time: 1 s, completed 11 Feb 2024, 17.43.12
</details>
### I had to add below as work around:
```
dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.14.2"
```
inspired from this issue: https://github.com/jwt-scala/jwt-scala/issues/403
### Qs:
- can this be avoided automatically moving forward? or does it have to be reported as issue, author of a lib does something to resolve it.
- I see https://mvnrepository.com/artifact/com.auth0/jwks-rsa/0.22.1 did pull in jackson-databind 2.15, hence above work around overrides this behavior.
### Reproduction
see description add the dependency and playframework, run the application it hsa the run time error
### Additional context
_No response_
### jwks-rsa version
0.22.1
### Java version
17.0.6
created above issue, after adjusting the dependencies, and also wrote the work around. (note the issue documented the latest versions of the libs used)