Last active
October 17, 2015 17:57
-
-
Save vkostyukov/0ca4ee48920c2e39c442 to your computer and use it in GitHub Desktop.
Finch Auth
This file contains hidden or 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
def auth0[A, B](doAuth: Request => Future[A])(e: Endpoint[B])(implicit | |
adjoin: PairAdjoin[A, B] | |
): Endpoint[adjoin.Out] = new Endpoint[adjoin.Out] { | |
def apply(input: Input): Option[(Input, () => Future[Output[adjoin.Out]])] = | |
e(input).map { | |
case (remainder, output) => | |
(remainder, () => for { | |
a <- doAuth(input.request) | |
ob <- output() | |
} yield b.copy(value = adjoin(a, b.value))) | |
} | |
} | |
case class User(id: Int) | |
val auth: Endpoint[A] => Endpoint[User :: A :: HNil] = auth0(req => Future.value(User(1))) | |
// Usage | |
auth(put("users" / int)) { (u: User, id: Int) => | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment