Skip to content

Instantly share code, notes, and snippets.

@marekzebrowski
Created March 29, 2016 18:28
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 marekzebrowski/c3c4d24b4ffbcb219036eb175233728a to your computer and use it in GitHub Desktop.
Save marekzebrowski/c3c4d24b4ffbcb219036eb175233728a to your computer and use it in GitHub Desktop.
akka-http-auth-help
def logUserIn(token:String):Future[Option[UserId]] = ???
val withUserId: Directive1[User.Id] = {
extractExecutionContext.flatMap { implicit ec =>
headerValueByType[Authorization]().flatMap { authHdr =>
{
onSuccess(logUserIn(authHdr)).flatMap {
case Some(userId) => provide[UserId](userId): Directive1[UserId]
case None => reject(MissingHeaderRejection(Authorization.name)): Directive1[UserId]
}
}
}
}
}
@marekzebrowski
Copy link
Author

[info] Compiling 1 Scala source to /Users/mar/git/sgrouples/target/scala-2.11/classes...
[warn] /Users/mar/git/sgrouples/src/main/scala/me/sgrouples/lib/rest/akkahttp/ChatApi.scala:91: Adaptation of argument list by inserting () has been deprecated: this is unlikely to be what you want.
[warn] signature: HeaderDirectives.headerValueByType[T <: akka.http.scaladsl.model.HttpHeader](magnet: akka.http.scaladsl.server.util.ClassMagnet[T]): akka.http.scaladsl.server.Directive1[T]
[warn] given arguments:
[warn] after adaptation: HeaderDirectives.headerValueByType((): Unit)
[warn] headerValueByTypeAuthorization.flatMap { authHdr =>
[warn] ^
[warn] one warning found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment