reflex-monad-auth: Utilities to split reflex app to authorized and not authorized contexts

[ library, mit, web ] [ Propose Tags ]

The package provides utilities to build in authorization in reflex application in agnostic way to the concrete authorization scheme.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
examples

Build examples executables.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1
Change log CHANGELOG.md
Dependencies base (>=4.7 && <4.15), containers, jsaddle (>=0.9 && <0.10), mtl (>=2.1 && <2.3), raw-strings-qq, reflex (>=0.4 && <0.9), reflex-dom, reflex-external-ref (>=1.0 && <1.1), reflex-monad-auth, text [details]
License MIT
Copyright 2020 Anton Gushcha
Author
Maintainer Anton Gushcha <ncrashed@protonmail.com>
Category Web
Source repo head: git clone https://github.com/ncrashed/reflex-monad-auth
Uploaded by NCrashed at 2020-11-25T16:02:25Z
Distributions
Executables reflex-monad-auth-example
Downloads 274 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for reflex-monad-auth-0.1.0.1

[back to package description]

reflex-monad-auth

The package provides utilities to build in authorization in reflex application in agnostic way to the concrete authorization scheme.

Features:

  • Split application into two contexts: authorized and not authorized. Provides helpers to dynamically switch between both.
  • Access to authorization specific state in authorized part of FRP network.

How to use

See (example)[./example/Main.hs] and run it with cabal new-run -f examples.

First, define you own authorization type:

data JWTAuth = JWTAuth {
    authToken :: !Text
  , authRole  :: !Role
  } deriving (Eq)

Use it in info type hole in AuthT monad transformer:

runAuthJWT :: (Reflex t, TriggerEvent t m, MonadIO m) => AuthT JWTAuth t m a -> m a
runAuthJWT = runAuth

main :: IO ()
main = mainWidgetWithCss css $ runAuthJWT frontend

Now you can use the main tool of the package liftAuth:

frontend :: (HasAuth t m, PerformEvent t m, TriggerEvent t m, MonadHold t m, DomBuilder t m, PostBuild t m, MonadIO m, MonadIO (Performable m), AuthInfo t m ~ JWTAuth) => m ()
frontend = void $ liftAuth notlogged logged
  where
    notlogged = do
      pressE <- buttonClass "outline" "Login"
      widgetHold_ (pure ()) $ text "Logging in..." <$ pressE
      signE <- delay 1 pressE
      loginE <- requestLoginFromServer signE -- Here you widget that ask server for token
      void $ signin loginE
    logged = do
      pressE <- buttonClass "outline" "Logout"
      text "We are authorized!"
      void $ signout pressE

Hacking

To enter shell with all dependencies for GHC, use ./ghc.sh script. Or use ./ghcjs.sh for GHCJS.