dmcg
09/27/2022, 9:26 AMval request = Request(GET, "/items?date=2021-01-02")
.withBasicAuth(Credentials("testUser", "testUser-pass"), "Authorization")
but is there a way to do the same without specifying the header name?dave
09/27/2022, 9:31 AMdmcg
09/27/2022, 9:33 AMdmcg
09/27/2022, 9:34 AMdmcg
09/27/2022, 9:35 AMprivate fun Request.withBasicAuth(credentials: Credentials) = withBasicAuth(credentials, "Authorization")
which does the job, but I want to be as vanilla as possibledave
09/27/2022, 9:38 AMRequest.header()
isn't it?dmcg
09/27/2022, 9:40 AMdave
09/27/2022, 9:43 AMAndrew O'Hara
09/30/2022, 3:08 AMBiDiLens<Request, Credentials>
for basic auth. I don't think it exists, but I can think of several uses for it.dmcg
09/30/2022, 3:18 PMAndrew O'Hara
09/30/2022, 7:22 PMdave
09/30/2022, 7:22 PMAndrew O'Hara
09/30/2022, 7:24 PMval (headerClientId, headerClientSecret) = request.header("Authorization")
?.trim()
?.takeIf { it.startsWith("Basic") }
?.substringAfter("Basic")
?.trim()
?.base64Decoded()
?.split(":", ignoreCase = false, limit = 2)
.let { parts ->
val clientId = parts?.getOrNull(0)?.let(::ClientId)
val clientSecret = parts?.getOrNull(1)?.let(::ClientSecret)
clientId to clientSecret
}
Andrew O'Hara
09/30/2022, 7:26 PMAndrew O'Hara
10/01/2022, 5:36 PMdave
10/01/2022, 6:08 PMdmcg
10/02/2022, 7:02 PM