All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.lhns.jwt.http4s.middleware.JwtSignerMiddleware.scala Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package de.lhns.jwt.http4s.middleware

import cats.Monad
import cats.data.OptionT
import de.lhns.jwt.http4s.syntax._
import de.lhns.jwt.{Jwt, JwtSigner}
import org.http4s.{ContextRequest, ContextRoutes, HttpRoutes}

object JwtSignerMiddleware {
  def apply[F[_] : Monad](signer: JwtSigner[F]): HttpRoutes[F] => ContextRoutes[Jwt, F] = { routes =>
    ContextRoutes[Jwt, F] { case ContextRequest(jwt, request) =>
      OptionT.liftF(signer.sign(jwt)).flatMap { signedJwt =>
        routes(request.withJwt(signedJwt))
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy