Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def AuthAction(user_pw: (String, String))(fun: Request[AnyContent] => SimpleResult) = Action{ r =>
- val (us, pw) = user_pw
- Logger.debug(r.headers.get("Authorization").toString)
- r.headers.get("Authorization").flatMap{
- case BasicAuth(`us`, `pw`) => Some(fun(r))
- case _ => None
- }.getOrElse(Unauthorized("Plz auth").withHeaders("WWW-Authenticate" -> """Basic realm="Secured""""))
- }
- object BasicAuth {
- object UsPw {
- def unapply(str: String) = str.fromBase64.split(":") match{
- case Array(us, pw) => Some(us -> pw)
- case _ => None
- }
- }
- def unapply(str: String): Option[(String, String)] = str.split(" ") match {
- case Array("Basic", UsPw(us, pw)) => Some(us -> pw)
- case _ => None
- }
- }
- def runka = AuthAction("abc"->"123"){ r =>
- Ok("Inloggning ok")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement