snaplet-sqlite-simple-jwt-auth-0.1.0.0: Snaplet for JWT authentication with snaplet-sqlite-simple

Safe HaskellNone
LanguageHaskell2010

Snap.Snaplet.SqliteSimple.JwtAuth.JwtAuth

Synopsis

Documentation

data User Source #

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.

Constructors

User 

Fields

data AuthFailure Source #

Types of errors that can happen on login or new user creation.

Constructors

UnknownUser

The login name does not exist.

DuplicateLogin

The login name already exists.

WrongPassword

Failed the password check.

sqliteJwtInit Source #

Arguments

:: 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.

createUser Source #

Arguments

:: 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.

login Source #

Arguments

:: Text

Login name of the user logging in

-> Text

Password

-> Handler b SqliteJwt (Either AuthFailure User) 

Login a user

writeJSON :: (MonadSnap m, ToJSON a) => a -> m () Source #

reqJSON :: (MonadSnap m, FromJSON b) => m b Source #

Demand the presence of JSON in the body assuming it is not larger than 50000 bytes.