Ktor OAuth Authentication and resource server library
- Add jitpack in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.papsign:KtorOAuthServer:-SNAPSHOT'
}
- Target the realease explicitly, during the experimental staes snapshots will likely break between versions.
- Implement a configuration like in the example
- Register the auth server endpoints with
Application.registerTestAuth()
- Register the resource server auth on your endpoint
- If you use KtorOenAPIGen,
inline fun NormalOpenAPIRoute.oauth2(vararg scopes: OAuthScope, crossinline route: OpenAPIAuthenticatedRoute<APIPrincipal>.()->Unit = {}): OpenAPIAuthenticatedRoute<APIPrincipal> {
return TestOpenAPIOAuthProvider(scopes.asList()).apply(this).apply {
route()
}
}
- If you use vanilla Ktor use
TestResourceServer.validateAuthCall
, if it is null it failed, else it has properly validated the call.
- If you use Exposed, you may need to implement the
requestWrapper
parameters with a database transaction