I'm in the middle of writing a blog post about that directive, it's one of the 
more "hardcore" ones in terms of hijacking scala mechanisms.

In this case it's hijacking auto-tupling.. To get rid of the message type:

headerValueByType[`Authorization`](())

If you give me a week or so there will be a full-in-details post about that 
directive (and recent improvements to it).

-- 
Cheers,
Konrad 'ktoso’ Malawski
Akka @ Lightbend

On 29 March 2016 at 20:40:26, Marek Żebrowski (marek.zebrow...@gmail.com) wrote:

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.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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

-- 
>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
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