Created
February 23, 2015 17:43
-
-
Save amolbrid/cb082f362d32afc33f57 to your computer and use it in GitHub Desktop.
TokenAuthenticator with implicit Session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait TokenAuthenticator { | |
def apiTokenAuth(implicit dbSession: Session) = new ApiTokenAuthenticator() | |
} | |
class ApiTokenAuthenticator(implicit val dbSession: Session, implicit val executionContext: ExecutionContext) extends HttpAuthenticator[User] { | |
override def getChallengeHeaders(httpRequest: HttpRequest): List[HttpHeader] = | |
`WWW-Authenticate`(HttpChallenge(scheme = "Token", realm = "Manta", params = Map.empty)) :: Nil | |
override def authenticate(credentials: Option[HttpCredentials], ctx: RequestContext): Future[Option[User]] = | |
Future.successful( | |
credentials.flatMap { | |
case GenericHttpCredentials(scheme, token, params) if scheme == "Token" => { | |
Users.authenticateWithToken(token) | |
} | |
case _ => None | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment