myndocs / kotlin-oauth2-server

Flexible OAuth2 server library. Support for multiple frameworks
Apache License 2.0
151 stars 25 forks source link

Form login authorize endpoint #67

Open adhesivee opened 5 years ago

adhesivee commented 5 years ago

Last changes allow to create form login on authorization endpoint. It might be unclear how to do it. This could be added to documentation.

MaaxGr commented 3 years ago

yeah. It's totally not clear, how to do this. Anything new on the documentation?

Schpammer commented 2 years ago

Hey! Are there any plans to add this to the documentation any time soon? I really like the simplicity of this lib but a form login is a must have in my usecase.

adhesivee commented 2 years ago

Still have to put some effort into this. Each framework has a special callback configuration for this, example: Javalin Ktor

Configuration can be done something like:

identityService = InMemoryIdentity()
        .identity {
            username = "foo"
            password = "bar"
        }
clientService = InMemoryClient()
        .client {
            clientId = "testapp"
            clientSecret = "testpass"
            scopes = setOf("trusted")
            redirectUris = setOf("https://localhost:7000/callback")
            authorizedGrantTypes = setOf(
                    AuthorizedGrantType.AUTHORIZATION_CODE,
                    AuthorizedGrantType.PASSWORD,
                    AuthorizedGrantType.IMPLICIT,
                    AuthorizedGrantType.REFRESH_TOKEN
            )
        }
tokenStore = InMemoryTokenStore()
authenticationCallback = { call, callRouter ->
  if (authenticated) {
       val context = KtorCallContext(call)
       CallContextBasicAuthenticator.handleAuthentication(context, callRouter)
  } else { 
    // render login page
  }
}

call in the callback will always be the context of the framework. So for Ktor this will be ApplicationCall and for Javalin this will be Context to give you full control over the request. It will invoke this callback for POST and GET