mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-24 14:31:55 +01:00
api: Simplify Authorization-Token extraction
This commit is contained in:
@@ -186,21 +186,10 @@ class ApiService extends SessionSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def extractAuthorizationTokenFromCookies(response: HttpResponse[_]): String = {
|
private def extractAuthorizationTokenFromCookies(response: HttpResponse[_]): String = {
|
||||||
response.headers.get("Set-Cookie") match {
|
response.cookies
|
||||||
case Some(cookieHeaders) =>
|
.find(_.getName == "Authorization-Token")
|
||||||
cookieHeaders
|
.map(_.getValue)
|
||||||
.find(_.startsWith("Authorization-Token="))
|
.getOrElse(throw new RuntimeException("Authorization-Token cookie not found in response"))
|
||||||
.flatMap { header =>
|
|
||||||
header.split(";").headOption.flatMap {
|
|
||||||
_.split("=", 2) match {
|
|
||||||
case Array(_, value) => Some(value)
|
|
||||||
case _ => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.getOrElse(throw new RuntimeException("Authorization-Token cookie not found in response headers"))
|
|
||||||
case None =>
|
|
||||||
throw new RuntimeException("No Set-Cookie headers found in response")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user