Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 22:18
Show Gist options
  • Save bandrzejczak/bf3d145f506a40022594ab3fd647e74e to your computer and use it in GitHub Desktop.
Save bandrzejczak/bf3d145f506a40022594ab3fd647e74e to your computer and use it in GitHub Desktop.
def authorized: Directive1[OAuth2Token] = {
bearerToken.flatMap {
case Some(token) =>
onComplete(tokenVerifier.verifyToken(token)).flatMap {
_.map(username => provide(OAuth2Token(token, username)))
.recover {
case ex =>
logger.error(ex, "Couldn't log in using provided authorization token")
reject(AuthorizationFailedRejection).toDirective[Tuple1[OAuth2Token]]
}
.get
}
case None =>
reject(AuthorizationFailedRejection)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment