For now, this library is only built with scala2.12.x
and play2.6.x
. Pull requests are welcome.
Add the latest version to your dependencies in build.sbt
, replacing x.x.x
with the newest version from
libraryDependencies += "com.lambdaminute" %% "play-basic-auth" % "x.x.x"
//MyApplicationLoader.scala
package controllers
import com.lambdaminute.playbasicauth.{BasicAuthFilter, User}
import play.api.ApplicationLoader.Context
import play.api._
import router.Routes
class MyApplicationLoader extends ApplicationLoader {
def load(context: Context) = {
new MyComponents(context).application
}
}
class MyComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with AssetsComponents {
val httpFilters = Seq(
new BasicAuthFilter(List(User(name = "Horse", password = "carrot")), realm = "everything"))
val homeController = new HomeController(controllerComponents)
lazy val router = new Routes(httpErrorHandler, homeController, assets)
}
//application.conf
play.application.loader=controllers.MyApplicationLoader
Please refer to the tests