Skip to content

Instantly share code, notes, and snippets.

@JoolsF
Last active June 10, 2016 11:15
Show Gist options
  • Save JoolsF/2fdce9c16c29a8511ce83992bbb31aa8 to your computer and use it in GitHub Desktop.
Save JoolsF/2fdce9c16c29a8511ce83992bbb31aa8 to your computer and use it in GitHub Desktop.
Basic auth akka-http
//http://doc.akka.io/docs/akka/2.4.3/scala/http/routing-dsl/directives/security-directives/authenticateBasic.html
Object Routes {
path("basicauthtest"){
authenticateBasic(realm = "secure site", BasicAuthenticator.myUserPassAuthenticator) { user =>
complete {
HttpResponse(entity = HttpEntity("SUCCESS"))
}
}
}
}
Object BasicAuthenticator {
private val hardCodedPassword = "qwerty" //For example purposes only
def myUserPassAuthenticator(credentials: Credentials): Option[String] = credentials match {
case [email protected](id) if p.verify(hardCodedPassword) => Some(id)
case _ => None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment