eed3si9n / gigahorse

Gigahorse is an HTTP client for Scala with multiple backend support.
http://eed3si9n.com/gigahorse
Apache License 2.0
121 stars 25 forks source link

Basic Auth not working with okhttp #77

Open adpi2 opened 2 years ago

adpi2 commented 2 years ago

Steps to reproduce

  1. Using "com.eed3si9n" %% "gigahorse-okhttp" % "0.6.0"
  2. 
    import gigahorse.support.okhttp.Gigahorse

val config = Gigahorse.config.withAuth(user, token, AuthScheme.Basic) val http = Gigahorse.http(config) val request = Gigahorse.url(s"https://api.github.com/repos/$privateRepo") // .withAuth(user, token, AuthScheme.Basic)

val response = Await.result(http.run(request), Duration.Inf) println(response.status)

where:
  - `user` is a Github user
  - `token` is a Github Personal Access Token with full control over private repositories
  - `privateRepo` is a private Github repository: e.g., `"org/private-repo"`

## Problem

It throws a `gigahorse.StatusError: Unexpected status: 404`.
Same result if I put the authentication in the request instead of the config.

## Expectation

It should return `OK`

## Notes

The same piece of code works with `gigahorse-akka-http`

## Workaround

I can manually set the `Authorization` header and it works:

```scala
val authorization = Base64.getEncoder().encodeToString((s"$user:$token").getBytes("UTF-8"))
val request = Gigahorse
  .url(s"https://api.github.com/repos/$privateRepo")
  .addHeaders(
     "Authorization" -> s"Basic $authorization"
)