nulab / scala-oauth2-provider

OAuth 2.0 server-side implementation written in Scala

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Proposed] Merge OAuth2AsyncProvider/OAuth2Provider

yllan opened this issue · comments

I have a controller both have sync action and async action, that doesn't work well with scala-oauth2-provider.

In order to use scala-oauth2-provider, I have to break the actions into two controllers by its async/sync behaviour, not their business logic.

Is it possible to have a single trait with different methods like authorize and authorizeAsync? Or do you have any insight about this?

👍 for authorize and authorizeAsync

Before we decided to change all interfaces of DataHandler to async by #18.
OAuthProvider's standard interface also change to async would be prefered.

This is just my idea.

We define OAuth2ProviderAwait trait, we can wrap await method with issueAccessToken and authorize methods on OAuthAsyncProvider.

trait OAuth2ProviderAwait {
  def await(f: Future[Result], timeout: Duration = 60.seconds): Result = Await.result(f, timeout)
}

object OAuth2Controller extends OAuth2AsyncProvider with OAuth2ProviderAwait {
  def index = Action.async { implicit request =>
    authorize(new MyDataHandler()) { authInfo =>
      Future.successful(Ok)
    }
  }

  def action = Action { implicit request =>
    await(authorize(new MyDataHandler()) { authInfo =>
      Future.successful(Ok)
    })
  }
}

Then, we don't need to create methods for sync and async into OAuth2Provider.
Finally, OAuth2Provider can also be integrated with OAuth2AsyncProvider.

I'm planing to release version 1.0.0 which means to not change destructive interface.
Before the release, I'm going to try the change.