-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathbrowserid.hs
54 lines (46 loc) · 1.33 KB
/
browserid.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
import Yesod.Core
import Yesod.Auth
import Yesod.Auth.BrowserId
import Data.Text (Text)
import Text.Hamlet (hamlet)
import Control.Monad.IO.Class (liftIO)
import Yesod.Form
import Network.Wai.Handler.Warp (run)
import Network.HTTP.Conduit
import Network.TLS
import Network.Wai.Middleware.RequestLogger
data BID = BID { httpManager :: Manager }
mkYesod "BID" [parseRoutes|
/ RootR GET
/after AfterLoginR GET
/auth AuthR Auth getAuth
|]
getRootR :: Handler ()
getRootR = redirect $ AuthR LoginR
getAfterLoginR :: Handler Html
getAfterLoginR = do
mauth <- maybeAuthId
defaultLayout $ toWidget [hamlet|
<p>Auth: #{show mauth}
|]
instance Yesod BID where
approot = ApprootStatic "http://localhost:3000"
instance YesodAuth BID where
type AuthId BID = Text
loginDest _ = AfterLoginR
logoutDest _ = AuthR LoginR
getAuthId = return . Just . credsIdent
authPlugins _ = [authBrowserId def]
authHttpManager = httpManager
maybeAuthId = lookupSession credsKey
instance RenderMessage BID FormMessage where
renderMessage _ _ = defaultFormMessage
main :: IO ()
main = do
m <- newManager conduitManagerSettings
toWaiApp (BID m) >>= run 3000 . logStdoutDev