com.sbuslab.http.directives.AuthDirectives.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of akka-http-tools Show documentation
Show all versions of akka-http-tools Show documentation
Tools for akka-http (marshaling, error handling, websockets, sbus support)
package com.sbuslab.http.directives
import scala.concurrent.Future
import akka.http.scaladsl.model.HttpRequest
import akka.http.scaladsl.server.{Directives, Route}
trait AuthProvider[T] {
def auth(request: HttpRequest): Future[T]
}
trait AuthDirectives extends Directives {
protected def auth[T](f: ⇒ Route)(implicit authProvider: AuthProvider[T]): Route =
auth { _: T ⇒ f }
protected def auth[T](inner: T ⇒ Route)(implicit authProvider: AuthProvider[T]): Route =
extractRequest { req ⇒
onSuccess(authProvider.auth(req))(inner)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy