I'm trying to write authenticator for akka-http using Authorization header. 
I came up with something:
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]
}
}
}
}
}It seems to work, but gives compilation warning:

[info] Compiling 1 Scala source to 
/Users/mar/git/sgrouples/target/scala-2.11/classes...
[warn] Adaptation of argument list by inserting () has been deprecated: 
this is unlikely to be what you want.
[warn] signature: HeaderDirectives.headerValueByTypeT <: 
akka.http.scaladsl.model.HttpHeader: akka.http.scaladsl.server.Directive1[T]
[warn] given arguments: 
[warn] after adaptation: HeaderDirectives.headerValueByType((): Unit)
[warn] headerValueByTypeAuthorization 
<https://gist.github.com/marekzebrowski/c3c4d24b4ffbcb219036eb175233728a>.flatMap
 
{ authHdr =>
[warn] ^
[warn] one warning found 

I'm puzzled if it is intended usage of this directive, or should I manually 
construct ClassMagnet[T]  for this Directive ?
In source code I can find example, that is constructed in the same way.

headerValueByType[Origin]() { origin ⇒
  complete(s"The first origin was ${origin.origins.head}")
}

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to