A Plugin to make authorization in ktor as easy as it gets
implementation("com.jaooooo:ktor-authorization:0.0.2")
class MyUser(override val roles: Set<Role>, ....) : RoleUser()
Set your User Roles' by your preferred authentication method.
Use one of the three pre-defined AuthType(s) or All Of them combined
WithAllRoles()
Applies logical AND to the required roles, a user must have them all
WithAnyRole()
Applies logical OR to the required roles, any role can do
withoutRoles()
Applies logical NOT to the required roles, a user can't have any of those
authenticate {
withAllRoles("Moderator","Provider") {
get("/secret-content") {
call.respondText("I love ktor, tell nobody!")
}
}
}