When I am accessing an Endpoint behind an authenti...
# ktor
d
When I am accessing an Endpoint behind an authentication and set the authentication to optional I can access this endpoint by web, but not by using a call from mobile. The response is "unauthorized" Server :
Copy code
routing {
    authenticate("serveradmin",optional = true) {
        get<Server.Connect> {
            call.respond("Hello")
        }
Client code :
Copy code
val credentials = Credentials.basic(serverEntity.username,serverEntity.password,Charsets.UTF_8)
val client = OkHttpClient.Builder().build()
val req  = Request.Builder().url(serverEntity.serverURL + "/server/status").addHeader("Authorization",credentials).build()
val call = client.newCall(req)
val response = call.execute()
val responseString = response.body?.string() ?: throw IOException()
As a response on mobile I get unauthorized 401, on Web I get the content of the route. I don't know if this is a problem of Ktor, or if I am doing something wrong by handling the unauthorized response. I tried using an authenticator, make a call without Credentials and respond to the challenge, but this can create an infinite loop of unauthorized.