Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data SqliteJwt = SqliteJwt {}
- data User = User {}
- data AuthFailure
- sqliteJwtInit :: String -> Snaplet Sqlite -> SnapletInit b SqliteJwt
- requireAuth :: (User -> Handler b SqliteJwt a) -> Handler b SqliteJwt a
- registerUser :: Handler b SqliteJwt ()
- loginUser :: Handler b SqliteJwt ()
- createUser :: Text -> Text -> Handler b SqliteJwt (Either AuthFailure User)
- login :: Text -> Text -> Handler b SqliteJwt (Either AuthFailure User)
- jsonResponse :: MonadSnap m => m ()
- writeJSON :: (MonadSnap m, ToJSON a) => a -> m ()
- reqJSON :: (MonadSnap m, FromJSON b) => m b
Documentation
User account User ID and login name.
If you need to store additional fields for your user accounts, persist them
in your application SQL tables and key them by userId
.
data AuthFailure Source #
Types of errors that can happen on login or new user creation.
UnknownUser | The login name does not exist. |
DuplicateLogin | The login name already exists. |
WrongPassword | Failed the password check. |
:: String | JWT secret signing key filename |
-> Snaplet Sqlite | The sqlite-simple snaplet |
-> SnapletInit b SqliteJwt |
Initializer for the sqlite-simple JwtAuth snaplet.
If the secret random key jwtSigningKeyFname
doesn't exist in the current
working directory, a new random key will be generated. Otherwise the
existing key will be loaded as the site signing key. This key is used to
sign the JWTs generated by the login procedure.
Initialization will automatically setup SQL tables used to store user accounts. It will also automatically upgrade the SQL schema if necessary.
requireAuth :: (User -> Handler b SqliteJwt a) -> Handler b SqliteJwt a Source #
Run a handler with the currently logged in user.
Verify authentication from the JWT token passed in the Authorization
header, and run the user provided action
with the logged in user.
On errors such as missing or malformed JWT or failure to verify the JWT, error out early and issue an HTTP 401 error.
registerUser :: Handler b SqliteJwt () Source #
:: Text | Login name of the user to be created |
-> Text | Password of the new user |
-> Handler b SqliteJwt (Either AuthFailure User) |
Create a new user.
:: Text | Login name of the user logging in |
-> Text | Password |
-> Handler b SqliteJwt (Either AuthFailure User) |
Login a user
jsonResponse :: MonadSnap m => m () Source #