zalando-stups / hutmann

Simple OAuth2 for Play! backend services
Other
3 stars 6 forks source link

Outdated mock example in readme #19

Open skokorin opened 6 years ago

skokorin commented 6 years ago

Three changes:

import akka.stream.Materializer
import org.zalando.hutmann.authentication._
import play.api.Configuration
import play.api.libs.ws.WSClient
import play.api.mvc._

import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}

trait Auth {
  def authAction(filter: User => Future[Boolean] = { user: User => Future.successful(true) },
      autoReject: Boolean = true, requestTimeout: Duration = 1.second)
      (implicit config: Configuration, ec: ExecutionContext, ws: WSClient, materializer: Materializer,
          parser: BodyParser[AnyContent]): OAuth2Action =
    new OAuth2Action(filter, autoReject, requestTimeout)(config.underlying, ec, ws, materializer, parser)
}

trait FakeAuth extends Auth {
  val userResult: Either[AuthorizationProblem, User]

  override def authAction(
      filter: User => Future[Boolean] = { user: User => Future.successful(true) },
      autoReject: Boolean = true, requestTimeout: Duration = 1.second
  )(implicit config: Configuration, ec: ExecutionContext, ws: WSClient, materializer: Materializer,
      parser: BodyParser[AnyContent]): OAuth2Action =
    new OAuth2Action(filter, autoReject, requestTimeout)(config.underlying, ec, ws, materializer, parser) {
      override def authenticate(requestHeader: RequestHeader): Future[Either[AuthorizationProblem, User]] =
        Future.successful(userResult)
    }
}
musiKk commented 6 years ago

I guess this has been forgotten when Play 2.6 support was introduced. Do you want to create a pull request for the updates?

skokorin commented 6 years ago

Hmm, something goes wrong, we have strange logging multiple:

DEBUG p.s.a.o.a.n.c.DefaultChannelPool@run:207 - Entry count for : %uri% : 1 ... Adding Candidate expired Channel ...

as soon as I've replaced OAuth2Action() with extends Auth ...