diff --git a/akka-http-core/src/main/scala/akka/http/model/headers/HttpCredentials.scala b/akka-http-core/src/main/scala/akka/http/model/headers/HttpCredentials.scala index d2dec483f2..b8a7975a1a 100644 --- a/akka-http-core/src/main/scala/akka/http/model/headers/HttpCredentials.scala +++ b/akka-http-core/src/main/scala/akka/http/model/headers/HttpCredentials.scala @@ -9,15 +9,23 @@ import akka.parboiled2.util.Base64 import akka.http.model.HttpCharsets._ import akka.http.util.{ Rendering, ValueRenderable } -sealed trait HttpCredentials extends ValueRenderable +sealed trait HttpCredentials extends ValueRenderable { + def scheme: String + def token: String + def params: Map[String, String] +} final case class BasicHttpCredentials(username: String, password: String) extends HttpCredentials { - def render[R <: Rendering](r: R): r.type = { + val cookie = { val userPass = username + ':' + password val bytes = userPass.getBytes(`ISO-8859-1`.nioCharset) - val cookie = Base64.rfc2045.encodeToChar(bytes, false) - r ~~ "Basic " ~~ cookie + Base64.rfc2045.encodeToChar(bytes, false) } + def render[R <: Rendering](r: R): r.type = r ~~ "Basic " ~~ cookie + + def scheme: String = "Basic" + def token = cookie.toString + def params = Map.empty } object BasicHttpCredentials { @@ -33,6 +41,9 @@ object BasicHttpCredentials { final case class OAuth2BearerToken(token: String) extends HttpCredentials { def render[R <: Rendering](r: R): r.type = r ~~ "Bearer " ~~ token + + def scheme: String = "Bearer" + def params: Map[String, String] = Map.empty } final case class GenericHttpCredentials(scheme: String, token: String,