The servant-auth-token-persistent package

[ Tags: bsd3, library, web ] [ Propose Tags ]

Please see README.md


[Skip to Readme]

Properties

Versions 0.4.0.0, 0.5.0.0, 0.5.1.0, 0.5.1.1, 0.6.0.0
Change log CHANGELOG.md
Dependencies aeson-injector (==1.0.*), base (>=4.7 && <5), bytestring (==0.10.*), containers (==0.5.*), monad-control (==1.0.*), mtl (==2.2.*), persistent (>=2.2 && <2.7), persistent-template (>=2.1 && <2.7), servant-auth-token (==0.5.*), servant-auth-token-api (==0.4.*), servant-server (>=0.9 && <0.12), text (==1.2.*), time (>=1.5 && <1.7), transformers (>=0.4 && <0.6), transformers-base (==0.4.*), uuid (==1.3.*) [details]
License BSD3
Copyright 2016 Anton Gushcha
Author NCrashed
Maintainer ncrashed@gmail.com
Category Web
Home page https://github.com/ncrashed/servant-auth-token#readme
Source repository head: git clone https://github.com/ncrashed/servant-auth-token
Uploaded Tue Aug 29 21:22:29 UTC 2017 by NCrashed
Distributions NixOS:0.6.0.0
Downloads 198 total (22 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
Last success reported on 2017-08-29 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for servant-auth-token-persistent-0.6.0.0

[back to package description]

servant-auth-token-persistent

Storage backend on persistent for servant-auth-token server.

An itegration of the backend is simple:

-- | Special monad for authorisation actions
newtype AuthM a = AuthM { unAuthM :: PersistentBackendT IO a }
  deriving (Functor, Applicative, Monad, MonadIO, MonadError ServantErr, HasStorage, HasAuthConfig)

-- | Execution of authorisation actions that require 'AuthHandler' context
runAuth :: AuthM a -> ServerM a
runAuth m = do
  cfg <- asks envAuthConfig
  pool <- asks envPool
  liftHandler $ ExceptT $ runPersistentBackendT cfg pool $ unAuthM m

Don't forget to add migration to your server startup (if you actually want automatic migrations):

-- | Create new server environment
newServerEnv :: MonadIO m => ServerConfig -> m ServerEnv
newServerEnv cfg = do
  let authConfig = defaultAuthConfig
  pool <- liftIO $ do
    pool <- createPool cfg
    -- run migrations
    flip runSqlPool pool $ runMigration S.migrateAllAuth
    -- create default admin if missing one
    _ <- runPersistentBackendT authConfig pool $ ensureAdmin 17 "admin" "123456" "admin@localhost"
    return pool
  let env = ServerEnv {
        envConfig = cfg
      , envAuthConfig = authConfig
      , envPool = pool
      }
  return env

See a full example in servant-auth-token-example-persistent.