Skip to content

A plugin that adds role based authorization to ktor servers

License

Notifications You must be signed in to change notification settings

JAOOOOO/ktor-authorization

Repository files navigation

ktor-authorization

image

A Plugin to make authorization in ktor as easy as it gets

How to use

install the plugin
implementation("com.jaooooo:ktor-authorization:0.0.2")
Extend RoleUser
class MyUser(override val roles: Set<Role>, ....) : RoleUser()

Set your User Roles' by your preferred authentication method.

Enjoy authorizing with eash <3

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

Example

authenticate {
  withAllRoles("Moderator","Provider") {
    get("/secret-content") {
      call.respondText("I love ktor, tell nobody!")
    }
  }  
}