Safe Haskell | None |
---|---|
Language | Haskell2010 |
- login :: (AuthApp a, AuthState b, MonadIO m) => UserKey -> Password -> WhebT a b m (Either AuthError AuthUser)
- logout :: (AuthApp a, AuthState b, MonadIO m) => WhebT a b m ()
- register :: (AuthApp a, MonadIO m) => AuthUser -> Password -> WhebT a b m (Either AuthError AuthUser)
- getCurrentUser :: (AuthState b, MonadIO m) => WhebT a b m (Maybe AuthUser)
- queryCurrentUser :: (AuthApp a, MonadIO m) => WhebT a b m (Maybe AuthUser)
- loginRequired :: (AuthState b, MonadIO m) => WhebHandlerT a b m -> WhebHandlerT a b m
- authMiddleware :: (AuthApp a, AuthState b, MonadIO m) => WhebMiddleware a b m
- data AuthUser = AuthUser {}
- data AuthContainer = forall r . AuthBackend r => AuthContainer r
- class SessionApp a => AuthApp a where
- getAuthContainer :: a -> AuthContainer
- class AuthState a where
- getAuthUser :: a -> PossibleUser
- modifyAuthUser :: (PossibleUser -> PossibleUser) -> a -> a
- class AuthBackend c where
- backendLogin :: (AuthApp a, MonadIO m) => SessionApp a => UserKey -> Password -> c -> WhebT a b m (Either AuthError AuthUser)
- backendRegister :: (AuthApp a, MonadIO m) => AuthUser -> Password -> c -> WhebT a b m (Either AuthError AuthUser)
- backendGetUser :: (AuthApp a, MonadIO m) => UserKey -> c -> WhebT a b m (Maybe AuthUser)
- backendLogout :: (AuthApp a, MonadIO m) => c -> WhebT a b m ()
- data AuthError
- type UserKey = Text
- type Password = Text
- type PwHash = Text
- makePwHash :: MonadIO m => Password -> WhebT a b m PwHash
- verifyPw :: Text -> Text -> Bool
- getUserSessionKey :: (AuthApp a, MonadIO m) => WhebT a b m Text
Main functions
login :: (AuthApp a, AuthState b, MonadIO m) => UserKey -> Password -> WhebT a b m (Either AuthError AuthUser) Source
Log a user in
register :: (AuthApp a, MonadIO m) => AuthUser -> Password -> WhebT a b m (Either AuthError AuthUser) Source
Register a user
getCurrentUser :: (AuthState b, MonadIO m) => WhebT a b m (Maybe AuthUser) Source
Get the current user from the handler state (Needs to be populated first
with authMiddleware
)
queryCurrentUser :: (AuthApp a, MonadIO m) => WhebT a b m (Maybe AuthUser) Source
Explicitly query a user with the backend. Since this is an IO hit, it is
better to use the middleware and getCurrentUser
loginRequired :: (AuthState b, MonadIO m) => WhebHandlerT a b m -> WhebHandlerT a b m Source
Checks if a user is logged in with getCurrentUser
and throws a 500
if they aren't.
Middleware
authMiddleware :: (AuthApp a, AuthState b, MonadIO m) => WhebMiddleware a b m Source
Auto-populates the handler state with the current user.
Types
data AuthContainer Source
forall r . AuthBackend r => AuthContainer r |
class SessionApp a => AuthApp a where Source
Interface for creating Auth backends
getAuthContainer :: a -> AuthContainer Source
class AuthState a where Source
Minimal implementation for a
getAuthUser :: a -> PossibleUser Source
modifyAuthUser :: (PossibleUser -> PossibleUser) -> a -> a Source
class AuthBackend c where Source
Interface for creating Auth backends
backendLogin :: (AuthApp a, MonadIO m) => SessionApp a => UserKey -> Password -> c -> WhebT a b m (Either AuthError AuthUser) Source
backendRegister :: (AuthApp a, MonadIO m) => AuthUser -> Password -> c -> WhebT a b m (Either AuthError AuthUser) Source
backendGetUser :: (AuthApp a, MonadIO m) => UserKey -> c -> WhebT a b m (Maybe AuthUser) Source
backendLogout :: (AuthApp a, MonadIO m) => c -> WhebT a b m () Source
AuthBackend UserData | In memory auth backend. User values will not persist after server restart. |