("ktor-arrow-server") { }
fun Application.users() = routing {
authenticateWith(jwt) {
route(Api.Users.list) {
val user = call.principal
val users = getAllUsers()
respond(users)
}
}
}
context(ctx: PrincipalContext)
val
ApplicationCall.principal: P
get() = this.typedPrincipal
```
> **Type hint** `this: Routing`
> **Type hint** `context(context(PrincipalContext, Unit))`
> **Type hint** `this: TypedRespondScope, Never, Parameters.Empty>`
### Typed authentication
Slide 71: /lambda-world-functional-kotlin-services/#/71
> **`SchemeWithRoles = emptySet())
object env { val issuer = "issuer"; val secret = "secret" }
fun getAllUsers(): List = emptyList()
// Example
val jwt: AuthenticationSchemeWithRoles> =
jwt("ktor-arrow-server") { }
.withRoles { it.roles }
fun Application.users() = routing {
authenticateWith(jwt, roles = [Role.Admin]) {
route(Api.Users.list) {
val user = call.principal
val roles = user.roles
val users = getAllUsers()
respond(users)
}
}
}
```
> **Type hint** `this: Routing`
> **Type hint** `context(context(RolesContext, PrincipalContext, Unit))`
> **Type hint** `this: TypedRespondScope, Never, Parameters.Empty>`