nulab / scala-oauth2-provider

OAuth 2.0 server-side implementation written in Scala
MIT License
537 stars 97 forks source link

Improve authorization handler #76

Closed tsuyoshizawa closed 8 years ago

tsuyoshizawa commented 8 years ago

I tried improving AuthorizationHandler interface. Ref #73

These methods's argument replaced with methods that only take a request: AuthorizationRequest.

And findClientUser unified to findUser.

Developer can handle request each grant type using AuthorizationRequesttype on findUser method like below:

    override def findUser(request: AuthorizationRequest): Future[Option[Account]] = DB.readOnly { implicit session =>
      request match {
        case request: PasswordRequest => Future.successful(Account.authenticate(request.username, request.password))
        case request: ClientCredentialsRequest =>
          val maybeUser = for {
            clientCredential <- request.clientCredential
          } yield OauthClient.findClientCredentials(clientCredential.clientId, clientCredential.clientSecret.getOrElse(""))
          Future.successful(maybeUser)
        case _ => Future.successful(None)
      }
    }
tsuyoshizawa commented 8 years ago

Hi @rmmeans

I created PR by following your advice. Could you review this?

rmmeans commented 8 years ago

I will try to review it this week. I'm actually in the middle of our Authentication & Authorization project which uses this library - so this will be good timing

rmmeans commented 8 years ago

I think this is an improvement for sure! I haven't had time to pull it down and look at integrating it into my Auth project though.

If you merge it - I'll be sure to pull it in and take a look. I'm still working on the Authenication side of my enterprises' Auth project. I have a working proof-of-concept using this library for the Authorization side. I'll be getting back over to the authorization side in the coming weeks.

Either way if you merge now or later, I'll be sure to pull it in to my project once I'm working on the Authorization side again!