UserIdPrincipal

Report a typo

Can we return UserIdPrincipal(credentials.password) instead of UserIdPrincipal(credentials.name) in the validate function?

install(Authentication) {
    basic("myAuth") {
        realm = "Access to the '/page' path"
        validate { credentials ->
            if (credentials.name == "Admin" && credentials.password == "2425") {
                UserIdPrincipal(credentials.password)
            } else {
                null
            }
        }
    }
}
routing {
    authenticate("myAuth") {
        get("/page") {
            call.respondText("Protected content! Name: ${call.principal<UserIdPrincipal>()?.name}")
        }
    }
}

You can open the IDE and check the result yourself.

Select one option from the list
___

Create a free account to access the full topic