Ktor: Client Basic Auth Feature not working at all

Created on 19 Mar 2019  路  2Comments  路  Source: ktorio/ktor

Ktor Version

1.1.3

Ktor Engine Used(client or server and name)

Client, Apache, CIO, Jetty

JVM Version, Operating System and Relevant Context

JVM 1.8, macOs

Feedback

Manually settings the header works tho.
Ktor Client 1.1.3 plain JVM, Apache engine.

HttpClient(Apache|Jetty|CIO) { // <-- all 3 engines have the problem
    install(Logging) {
        level = LogLevel.ALL
    }
    install(Auth) {
        basic {
            username = Settings.mainServerUsername
            password = Settings.mainServerPassword
        }
    }
    install(JsonFeature) {
        serializer = KotlinxSerializer()
    }
}

Logging output is:

11:16:45.182 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - REQUEST: http://localhost:8080/api/newCamera
11:16:45.182 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - METHOD: HttpMethod(value=POST)
11:16:45.182 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - HEADERS
11:16:45.182 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - -> Accept: application/json
11:16:45.183 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - BODY Content-Type: application/json
11:16:45.184 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - BODY START
11:16:45.184 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - "TEST"
11:16:45.184 [DefaultDispatcher-worker-1] INFO  io.ktor.client.HttpClient - BODY END
11:16:45.290 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - RESPONSE: 401 
11:16:45.291 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - METHOD: HttpMethod(value=POST)
11:16:45.291 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - FROM: http://localhost:8080/api/newCamera
11:16:45.292 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - HEADERS
11:16:45.292 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - -> WWW-Authenticate: Basic realm=local-server, charset=UTF-8
11:16:45.292 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - -> Connection: keep-alive
11:16:45.292 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - -> Content-Length: 0
11:16:45.292 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - -> Date: Tue, 19 Mar 2019 10:16:45 GMT
11:16:45.293 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - BODY Content-Type: null
11:16:45.293 [DefaultDispatcher-worker-2] INFO  io.ktor.client.HttpClient - BODY START

Having serialization problem as well.

bug

Most helpful comment

Basic auth still not working on 1.4.0

All 2 comments

Hi @lamba92, thanks for the report.
The issue was in the logging ResponseObserver.
It fixed in the develop and I also add the test to check for your case.

Basic auth still not working on 1.4.0

Was this page helpful?
0 / 5 - 0 ratings