Skip to content


Repository files navigation


CI Status Gitter Chat Maven Central Cats friendly Scala Steward badge

Opinionated JWT authentication library for http4s.


jwt-scala is being used to encode and decode JWT tokens.

Add the following dependency to your build.sbt (check latest version on the badge):

"dev.profunktor" %% "http4s-jwt-auth" % Version

This library currently only supports the stable 0.23 series of http4s.


import cats.effect.IO
import cats.implicits._
import dev.profunktor.auth._
import dev.profunktor.auth.jwt._
import pdi.jwt._
import org.http4s._

case class AuthUser(id: Long, name: String)

// i.e. retrieve user from database
val authenticate: JwtToken => JwtClaim => IO[Option[AuthUser]] =
  token => claim => AuthUser(123L, "joe").some.pure[IO]

val jwtAuth    = JwtAuth.hmac("53cr3t", JwtAlgorithm.HS256)
val middleware = JwtAuthMiddleware[IO, AuthUser](jwtAuth, authenticate)

val routes: AuthedRoutes[AuthUser, IO] = ???
val securedRoutes: HttpRoutes[IO] = middleware(routes)

Build microsite

You need to have jekyll installed before running the following command:

$ sbt makeMicrosite
$ cd site/target/site 
$ jekyll serve

Or you can use nix develop by leveraging the flake.nix in this repo.


This library is quite opinionated, use with caution. Examples and docs coming soon!

If you would like to see support for any other functionality come have a chat in the Gitter channel!