hejfelix / play-basic-auth   0.1.15

MIT License GitHub

A basic auth filter for play

Scala versions: 2.12

play-basic-auth

Maven Central Build Status

forthebadge forthebadge forthebadge forthebadge

A basic auth filter for play

Dependencies

For now, this library is only built with scala2.12.x and play2.6.x. Pull requests are welcome.

Usage:

Add the latest version to your dependencies in build.sbt, replacing x.x.x with the newest version from Maven Central

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

More examples

Please refer to the tests