path("authenticate") {
import JsonProtocol._
get(complete_future(authenticate))
}
def authenticate (неявное http_request: HttpRequest) = Future {
val auth_header = http_request.headers.filter(x=>x.name()=="Authorization")
println(auth_header(0))
val header = Option(auth_header(0).value).getOrElse("")
header.split("""\s""") match {
case Array("Basic",userPass) =>
new String(Base64.getDecoder.decode(userPass),"UTF-8").split(":") match{
case Array(user,password) => {
val cookie = authService.authenticate(user, password)
println("COOKIE "+cookie)
val raw_cookie = authService.get_header(user,password)
val cookies = parse_cookie(raw_cookie).toList.flatten
// setCook ie (headers.HttpCook ie ("TMS_AUTHN_TOKEN", cook ie)) cookies.map (x => setCook ie (x))
ok(AuthResult(true,"User authenticated successfully"))
}
case _ => credentials_not_provided
}
case _ => credentials_not_provided
}
}