On 02/01/17 21:12, Konrad Malawski wrote:
How about sharing in a blog or docs about how to go about building such?
I think that'd be very interesting to people who're faced similar questions
as you were just a few days ago :)
Here's what I ended up with:
def authBasicHttp: Directive1[Login] = {
authenticateBasicAsync(null, {
case cp @ Credentials.Provided(user) =>
Future(Users.userPassword(user).flatMap { p => if (cp.verify(p))
Some(Login(user)) else None })
case _ => Future.successful(None)
})
}
def authXHeader: Directive1[Login] = {
(headerValueByName("X-Auth-User") &
headerValueByName("X-Auth-Key")).tflatMap { up =>
onComplete(Future { Users.validUser(up._1, up._2) }).flatMap {
case Success(Some(l)) => provide(l)
case Success(None) => reject(AuthRejection("invalid credentials"))
case Failure(e) => reject(AuthRejection("internal error"))> }
}
}
def authXSession: Directive1[Login] = {
headerValueByName("X-Auth-Session").flatMap { s =>
onComplete(Future { Users.validSession(s) }).flatMap {
case Success(Some(l)) => provide(l)
case Success(None) => reject(AuthRejection("invalid credentials"))
case Failure(e) => reject(AuthRejection("internal error"))
}
}
}
def combinedAuth = authBasicHttp | authXHeader | authXSession
--
Alan Burlison
--
--
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.