# Build and Secure APIs with Scala and the Play Framework

**URL:** <https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551>\
**Category:** Blog Discussions\
**Tags:** scala\
**Created:** [November 30, 2018, 11:36am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551 "2018-11-30T11:36:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve.hobbs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steve.hobbs/32/13234_2.png) [@steve.hobbs](https://community.auth0.com/u/steve.hobbs)\
**Post date:** [November 30, 2018, 11:36am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/1 "2018-11-30T11:36:15Z")

</div>

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](https://auth0.com/blog/build-and-secure-a-scala-play-framework-api/)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [August 22, 2019, 9:08am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/2 "2019-08-22T09:08:18Z")

</div>

Hey everyone! We’re closing this thread for now but feel free to reopen it anytime you feel like asking a question!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [August 22, 2019, 9:08am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/3 "2019-08-22T09:08:21Z")

</div>



---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [September 7, 2019, 3:58pm UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/4 "2019-09-07T15:58:50Z")

</div>



---

<div class="post-metadata">

**Author:** ![hubca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hubca/32/18012_2.png) [@hubca](https://community.auth0.com/u/hubca)\
**Post date:** [December 16, 2019, 6:17pm UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/5 "2019-12-16T18:17:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2019, 9:15am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/6 "2019-12-17T09:15:14Z")

</div>

Thanks for providing that feedback! Let me tag the article author here @steve.hobbs so he can address that once he’s online

---

<div class="post-metadata">

**Author:** ![steve.hobbs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steve.hobbs/32/13234_2.png) [@steve.hobbs](https://community.auth0.com/u/steve.hobbs)\
**Post date:** [December 17, 2019, 10:26am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/7 "2019-12-17T10:26:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2019, 10:52am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/8 "2019-12-17T10:52:36Z")

</div>

Thanks a loot for sharing it Steve!

---

<div class="post-metadata">

**Author:** ![hubca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hubca/32/18012_2.png) [@hubca](https://community.auth0.com/u/hubca)\
**Post date:** [December 17, 2019, 11:09am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/9 "2019-12-17T11:09:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 18, 2019, 11:45am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/10 "2019-12-18T11:45:53Z")

</div>

Thanks for the feedback on the article!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 5, 2021, 11:49am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/11 "2021-11-05T11:49:14Z")

</div>



---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 7, 2022, 1:53pm UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/12 "2022-03-07T13:53:58Z")

</div>



---

<div class="post-metadata">

**Author:** ![phelps-sg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/phelps-sg/32/40228_2.png) [@phelps-sg](https://community.auth0.com/u/phelps-sg)\
**Post date:** [September 25, 2022, 11:21am UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/13 "2022-09-25T11:21:58Z")

</div>

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](https://github.com/auth0-blog/scala-api-sample/pull/1).

---

<div class="post-metadata">

**Author:** ![mish](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@mish](https://community.auth0.com/u/mish)\
**Post date:** [February 4, 2024, 7:05pm UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/14 "2024-02-04T19:05:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mish](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@mish](https://community.auth0.com/u/mish)\
**Post date:** [February 11, 2024, 7:46pm UTC](https://community.auth0.com/t/build-and-secure-apis-with-scala-and-the-play-framework/18551/15 "2024-02-11T19:46:51Z")

</div>

> <https://github.com/auth0/jwks-rsa-java/issues/192>
>
> \### 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)
