Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jwt authentication support #8

Open
Globegitter opened this issue Dec 3, 2019 · 1 comment
Open

jwt authentication support #8

Globegitter opened this issue Dec 3, 2019 · 1 comment

Comments

@Globegitter
Copy link

So, hopefully this will be the last one. In our application we have

install(Authentication) {
        jwt(configure = authenticationProvider)
    }

and I would like for routes within the apiRouting block to be able to make use of that authentication provider. For normal kotlin routes I can just use the authenticate block but that does not seem to exist in apiRouting. Is this use-case supported or not?

@Wicpar
Copy link
Collaborator

Wicpar commented Dec 3, 2019

no convenient implementation exists.
you need to implement it yourself by implementing AuthProvider<PrincipalObject>
and creating a route selector that registers it:

inline fun<T> NormalOpenAPIRoute.auth(privider: AuthProvider<T>, crossinline route: OpenAPIAuthenticatedRoute<T>.()->Unit = {}): OpenAPIAuthenticatedRoute<T> {
    return provider.apply(this).apply {
        route()
    }
}

there was an implementation with oauth, which would be a good example:
https://github.com/papsign/Ktor-OpenAPI-Generator/blob/b5269bdab0bb40dbb36ec6a2b8f544418601a456/src/main/kotlin/com/papsign/ktor/openapigen/interop/OAuth2Provider.kt
look at the inner class OAuth2Provider

the problem was that the oauth system in ktor is for clients only and not resource servers.
i have implemented an oauth server framework, and will release it publicly once it is stable and maintainable.

Feel free to do a pull request if you create a proper implementation for convenient JWT handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants