com.lightbend.lagom.scaladsl.api.transport.HeaderFilter acess to play.api.Config

Hello, I need to get some application.conf parameters in the HeaderFilter I had implemented using HeaderFilters and I tried to inject Configuration (play.api.Configuration) in my header filter implementation and also use it as implicit without success. Is there a way to properly have the Play configuration available in the header filter?

play.api.Configuration is deprecated…

I guess you can do the following.

class MyFilter(config: Config) extends HeaderFilter {
  // use config here

trait Service {
  def config: Config

  def descriptor = {
      new MyFilter(config)

class ServiceImpl(val config: Config) extends Service

When you wire ServiceImpl with macwire, you get Config injected for you and it will be passed to MyFilter.

Hello, I created one simple project to test the case header-filter-config, when defining a unit in the API definition the project compilation fails with the error:

Can't generate a Lagom client for my.lagom.issue.api.HeaderFilterService since the following abstract methods don't return service calls or topics: config

It seems that any def in the Service API definition should return a call or topic…

Even though trying to create a parameter in the HeaderFilter (moving from object to class) I receive in the API

[info] Compiling 1 Scala source to /home/fernando.hackbart/Documents/Projects/SPMS/poc/xxx/header-filter-config/header-filter-api/target/scala-2.12/classes ...
[error] /home/fernando.hackbart/Projects/header-filter-config/header-filter-api/src/main/scala/my/lagom/issue/api/HeaderFilterService.scala:19:45: my.lagom.issue.code.MyConfigHeaderFilter.type does not take parameters
[error]       .withHeaderFilter(MyConfigHeaderFilter(config))
[error]                                             ^
[error] one error found
[error] (header-filter-api / Compile / compileIncremental) Compilation failed

I have a class with parameter and an object without parameter and it tries to use the object always, I think I should have to inject the configuration in the object somehow…

I’m afraid that there isn’t a good way to inject configuration into a header filter (see Header filters are mostly useful for mechanical transformations of the headers.

Depending on what you’re trying to do, it might be more appropriate to use a Play filter, or service call composition.

What I am trying to do is to make available a public certificate to validate a signed JWT token… As I am running on Kubernetes the certificate is available as a secret and I planning to have it available using the application.conf. For now I am doing a dirty System.getEnv(). I am not even sure the application.conf way is the best way…

That sounds like a good use case for service call composition. This will allow you to pass the validated data from the token through to the service call method itself where you can use it in your business logic.

I see, I will split the logic to, in the header filter ensure that the JWT token is present in the request and then validate and extract the token content in the composition.

Thank you