Skip to content

Instantly share code, notes, and snippets.

@Algiras
Created February 10, 2020 12:49
Show Gist options
  • Save Algiras/829bd17185a7ccbabc26ca82ed092945 to your computer and use it in GitHub Desktop.
Save Algiras/829bd17185a7ccbabc26ca82ed092945 to your computer and use it in GitHub Desktop.
def authenticator(userStore: IdentityStore[IO, UserId, User]) = for {
tokens <- Ref.of[IO, Map[SecureRandomId, TSecBearerToken[UserId]]](Map.empty)
} yield BearerTokenAuthenticator[IO, UserId, User](
userStore,
tokenStore(tokens),
TSecTokenSettings(
expiryDuration = 10.minutes,
maxIdle = None
))
def httpApp(userStore: UserStore) = authenticator
.map(auth => {
val loginRoutes = login.loginRoute(authenticator, userStore.checkPassword)
SecuredRequestHandler(auth).liftService(privateRoutes) <+> routes
}).map(_.orNotFound)
def run(args: List[String]): IO[ExitCode] =
httpApp(UserStore(
UsernamePasswordCredentials("username", "pass")
)).flatMap(server(_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment