Hello all. I'm trying to use Keycloak with ktor, b...
# ktor
r
Hello all. I'm trying to use Keycloak with ktor, but I have a problem: When trying to access a protected endpoint, even passing the bearer token, it still asks for a login and password. why? My code:
Copy code
val keycloakAddress = "<http://localhost:9999>"

val keycloakProvider = OAuthServerSettings.OAuth2ServerSettings(
  name = "keycloak",
  authorizeUrl = "$keycloakAddress/auth/realms/test/protocol/openid-connect/auth",
  accessTokenUrl = "$keycloakAddress/auth/realms/test/protocol/openid-connect/token",
  clientId = "api-access",
  clientSecret = "54f48c9e-5563-4677-9278-72078894baf3",
  accessTokenRequiresBasicAuth = false,
  requestMethod = <http://HttpMethod.Post|HttpMethod.Post>, // must POST to token endpoint
  defaultScopes = listOf("admin")
)

  install(Authentication) {
    oauth("keycloak") {
      client = HttpClient(Apache)
      providerLookup = { keycloakProvider }
      urlProvider = { "<http://localhost:8080/oauth>" }
    }
  }

  routing {
    get("/") {
      call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
    }
    authenticate("keycloak") {
      get("/oauth") {
        call.respondText("HELLO WORLD SECRET!", contentType = ContentType.Text.Plain)
      }
    }
  }
­čĹÇ 1