Skip to content

Instantly share code, notes, and snippets.

@kmikulski
Created December 5, 2018 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmikulski/9f6b92c494aeb9b41186c77d2ac235af to your computer and use it in GitHub Desktop.
Save kmikulski/9f6b92c494aeb9b41186c77d2ac235af to your computer and use it in GitHub Desktop.
the description for this gist
trait AuthorizationHandler extends SprayJsonSupport with DefaultJsonProtocol {
implicit def executionContext: ExecutionContext
implicit def materializer: ActorMaterializer
implicit def system: ActorSystem
def log: LoggingAdapter
def authorize: Directive1[AccessToken] =
extractCredentials.flatMap {
case Some(OAuth2BearerToken(token)) =>
onComplete(verifyToken(token)).flatMap {
case Success(Some(t)) =>
provide(t)
case _ =>
log.warning(s"token $token is not valid")
reject(AuthorizationFailedRejection)
}
case _ =>
log.warning("no token present in request")
reject(AuthorizationFailedRejection)
}
def verifyToken(token: String): Future[Option[AccessToken]] = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment