Best way to implement authorization (not authentication)?
The docs have a chapter „Authentication & Authorization“ but it feels like a lie, because it only talks about authentication afaics.
I found this blog from 2020 where they create a new phase and add an interceptor to it to do authorization checks:
https://www.ximedes.com/2020-09-17/role-based-authorization-in-ktor/
Would you recommend this or is there now a better way to implement authorization?
👍 1
➕ 1
d
Dominik Sandjaja
05/26/2023, 6:48 AM
When I did this I created a
RouteScopedPlugin
which then hooks into the
on(AuthenticationChecked)
hook.
If desired I can try to create a small example at some point and put it on GitHub.
Thanks for the answers!
Now that you pointed me to the sample, I even found the link to the sample in the ktor docs hidden under "Supported authentication types -> Custom".
Also, I found a good explanation that uses the same way with