I have unauthenticated routes and authenticated routes in my Akka/Spray
DSL. Below is simplified version of the code
val nakedRoutes = pathPrefix("user") {
post {
entity(as[UserNew]) { user =>
(validate(EmailValidator.getInstance().isValid(user.email), s"Invalid
email address ${user.email}") & validate(!user.password.isEmpty, "Password
should not be empty")) {
complete {
UserWire(new ObjectId(), user.firstName, user.lastName, user.email,
user.company, user.role, new ObjectId())
}
}
}
}}
val myAuthorization: Directive[Tuple1[String]] =
(headerValueByName("X-API-Token") |
parameter("token")).tflatMap[Tuple1[String]]{
case Tuple1(token) => if (!token.isEmpty) provide(token.reverse) else
complete(StatusCodes.Forbidden -> "API token is not provided")
}
val authenticatedRoutes = myAuthorization { user =>
get { complete { "" } }}
val routes = (decodeRequest & encodeResponse) {
authenticatedRoutes ~ nakedRoutes
}
The idea is that user makes POST /user request, gets token and uses it for
authenticated routes.
The problem I have is that when validation of email fails I get incorrect
rejection
Request is missing required HTTP header 'X-API-Token'
Why doesn't it throw last occurred rejection ? How does framework pick
rejection out of multiple rejections ?
--
>>>>>>>>>> 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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.