From b589057be237fdbaafa238beb04f304fc1bfdbb3 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 24 Sep 2011 21:21:38 +0300 Subject: [PATCH] Added openid.hs sample for yesod-auth --- yesod-auth/openid.hs | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 yesod-auth/openid.hs diff --git a/yesod-auth/openid.hs b/yesod-auth/openid.hs new file mode 100644 index 00000000..e12cbe2a --- /dev/null +++ b/yesod-auth/openid.hs @@ -0,0 +1,48 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE MultiParamTypeClasses #-} +import Yesod.Core +import Yesod.Auth +import Yesod.Auth.OpenId +import Data.Text (Text) +import Text.Hamlet (hamlet) +import Control.Monad.IO.Class (liftIO) +import Yesod.Form +import Network.Wai.Handler.Warp (run) + +data BID = BID + +mkYesod "BID" [parseRoutes| +/ RootR GET +/after AfterLoginR GET +/auth AuthR Auth getAuth +|] + +getRootR :: Handler () +getRootR = redirect RedirectTemporary $ AuthR LoginR + +getAfterLoginR :: Handler RepHtml +getAfterLoginR = do + mauth <- maybeAuthId + defaultLayout $ addHamlet [hamlet| +

Auth: #{show mauth} +|] + +instance Yesod BID where + approot _ = "http://localhost:3000" + +instance YesodAuth BID where + type AuthId BID = Text + loginDest _ = AfterLoginR + logoutDest _ = AuthR LoginR + getAuthId = return . Just . credsIdent + authPlugins = [authOpenId] + +instance RenderMessage BID FormMessage where + renderMessage _ _ = defaultFormMessage + +main :: IO () +main = toWaiApp BID >>= run 3000 +