Skip to content
🔒 Opinionated JWT authentication library for Http4s
Scala
Branch: master
Clone or download
Latest commit 8434a2e Oct 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci CI build + mergify + COC + tuning microsite Sep 24, 2019
.github Create FUNDING.yml Sep 25, 2019
core/src adding common functions + updating auth function Oct 18, 2019
project Update sbt to 1.3.3 Oct 14, 2019
site/src/main updating docs Oct 18, 2019
.gitignore
.mergify.yml CI build + mergify + COC + tuning microsite Sep 24, 2019
.scalafmt.conf
CODE_OF_CONDUCT.md CI build + mergify + COC + tuning microsite Sep 24, 2019
CONTRIBUTING.md CI build + mergify + COC + tuning microsite Sep 24, 2019
README.md Adding dep to build.sbt Oct 18, 2019
build.sbt adding common functions + updating auth function Oct 18, 2019

README.md

http4s-jwt-auth

CircleCI Gitter Chat Maven Central Cats friendly MergifyStatus

Opinionated JWT authentication library for http4s.

Dependencies

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

Usage

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(JwtSecretKey("53cr3t"), JwtAlgorithm.HS256)
val middleware = JwtAuthMiddleware[IO, AuthUser](jwtAuth, authenticate)

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

Notes

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!

You can’t perform that action at this time.