packages feed

wai-session-clientsession (empty) → 0.1

raw patch · 5 files changed

+92/−0 lines, 5 filesdep +basedep +bytestringdep +cerealsetup-changed

Dependencies added: base, bytestring, cereal, clientsession, errors, transformers, wai-session

Files

+ COPYING view
@@ -0,0 +1,13 @@+Copyright © 2012, Stephen Paul Weber <singpolyma.net>++Permission to use, copy, modify, and/or distribute this software for any+purpose with or without fee is hereby granted, provided that the above+copyright notice and this permission notice appear in all copies.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ Network/Wai/Session/ClientSession.hs view
@@ -0,0 +1,34 @@+module Network.Wai.Session.ClientSession (clientsessionStore) where++import Control.Monad+import Data.ByteString (ByteString)+import Control.Monad.IO.Class (liftIO, MonadIO)+import Network.Wai.Session (Session, SessionStore)+import Data.IORef+import Control.Error (hush)++import Web.ClientSession (Key, encryptIO, decrypt)+import Data.Serialize (encode, decode, Serialize) -- Use cereal because clientsession does++-- | Session store that keeps all content in a 'Serialize'd cookie encrypted+-- with 'Web.ClientSession'+--+-- WARNING: This session is vulnerable to sidejacking,+-- use with TLS for security.+clientsessionStore :: (Serialize k, Serialize v, Eq k, MonadIO m) => Key -> SessionStore m k v+clientsessionStore cryptKey (Just encoded) =+	case hush . decode =<< decrypt cryptKey encoded of+		Just sessionData -> backend cryptKey sessionData+		-- Bad cookie is the same as no cookie+		Nothing -> clientsessionStore cryptKey Nothing+clientsessionStore cryptKey Nothing = backend cryptKey []++backend :: (Serialize k, Serialize v, Eq k, MonadIO m) => Key -> [(k, v)] -> IO (Session m k v, IO ByteString)+backend cryptKey sessionData = do+	-- Don't need threadsafety because we only hand this IORef to an Application+	-- through a single Request.+	ref <- newIORef sessionData+	return ((+			(\k -> lookup k `liftM` liftIO (readIORef ref)),+			(\k v -> liftIO (modifyIORef ref (((k,v):) . filter ((/=k) . fst))))+		), encryptIO cryptKey =<< encode `fmap` readIORef ref)
+ README view
@@ -0,0 +1,3 @@+Provides a session store for use with wai-session.++See example/Main.hs in git for example usage.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ wai-session-clientsession.cabal view
@@ -0,0 +1,39 @@+name:            wai-session-clientsession+version:         0.1+cabal-version:   >= 1.8+license:         OtherLicense+license-file:    COPYING+category:        Web+copyright:       © 2012 Stephen Paul Weber+author:          Stephen Paul Weber <singpolyma@singpolyma.net>+maintainer:      Stephen Paul Weber <singpolyma@singpolyma.net>+stability:       experimental+tested-with:     GHC == 7.0.3+synopsis:        Session store based on clientsession+homepage:        https://github.com/singpolyma/wai-session-clientsession+bug-reports:     https://github.com/singpolyma/wai-session-clientsession/issues+build-type:      Simple+description:+        Provides a session store for use with wai-session.+        .+        See example/Main.hs in git for example usage.++extra-source-files:+        README++library+        exposed-modules:+                Network.Wai.Session.ClientSession++        build-depends:+                base == 4.*,+                bytestring,+                transformers,+                cereal,+                clientsession,+                errors,+                wai-session++source-repository head+        type:     git+        location: git://github.com/singpolyma/wai-session-clientsession.git