Created
December 5, 2018 21:30
-
-
Save kmikulski/9f6b92c494aeb9b41186c77d2ac235af to your computer and use it in GitHub Desktop.
the description for this gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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