Auth now usable
This commit is contained in:
parent
ca3c5b098d
commit
27981e04f4
@ -25,7 +25,10 @@ module Yesod.Helpers.Auth
|
|||||||
, displayName
|
, displayName
|
||||||
, redirectLogin
|
, redirectLogin
|
||||||
, Auth (..)
|
, Auth (..)
|
||||||
|
, AuthRoutes (..)
|
||||||
, siteAuth
|
, siteAuth
|
||||||
|
, LoginType (..)
|
||||||
|
, YesodAuth (..)
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Web.Encodings
|
import Web.Encodings
|
||||||
@ -45,15 +48,16 @@ import Control.Exception (Exception)
|
|||||||
|
|
||||||
data LoginType = OpenId | Rpxnow
|
data LoginType = OpenId | Rpxnow
|
||||||
|
|
||||||
|
class Yesod master => YesodAuth master where
|
||||||
|
onRpxnowLogin :: Rpxnow.Identifier -> GHandler Auth master ()
|
||||||
|
|
||||||
data Auth = Auth
|
data Auth = Auth
|
||||||
{ defaultDest :: String
|
{ defaultDest :: String
|
||||||
, onRpxnowLogin :: forall master. Yesod master
|
|
||||||
=> Rpxnow.Identifier -> GHandler Auth master ()
|
|
||||||
, rpxnowApiKey :: Maybe String
|
, rpxnowApiKey :: Maybe String
|
||||||
, defaultLoginType :: LoginType
|
, defaultLoginType :: LoginType
|
||||||
}
|
}
|
||||||
|
|
||||||
$(mkYesodSub "Auth" [''Yesod] [$parseRoutes|
|
$(mkYesodSub "Auth" [''YesodAuth] [$parseRoutes|
|
||||||
/check Check GET
|
/check Check GET
|
||||||
/logout Logout GET
|
/logout Logout GET
|
||||||
/openid OpenIdR GET
|
/openid OpenIdR GET
|
||||||
@ -118,7 +122,7 @@ getOpenIdComplete = do
|
|||||||
redirectToDest RedirectTemporary $ defaultDest y
|
redirectToDest RedirectTemporary $ defaultDest y
|
||||||
attempt onFailure onSuccess res
|
attempt onFailure onSuccess res
|
||||||
|
|
||||||
handleRpxnowR :: Yesod master => GHandler Auth master ()
|
handleRpxnowR :: YesodAuth master => GHandler Auth master ()
|
||||||
handleRpxnowR = do
|
handleRpxnowR = do
|
||||||
ay <- getYesod
|
ay <- getYesod
|
||||||
apiKey <- case rpxnowApiKey ay of
|
apiKey <- case rpxnowApiKey ay of
|
||||||
@ -137,8 +141,7 @@ handleRpxnowR = do
|
|||||||
(s:_) -> s
|
(s:_) -> s
|
||||||
(d:_) -> d
|
(d:_) -> d
|
||||||
ident <- liftIO $ Rpxnow.authenticate apiKey token
|
ident <- liftIO $ Rpxnow.authenticate apiKey token
|
||||||
auth <- getYesod
|
onRpxnowLogin ident
|
||||||
onRpxnowLogin auth ident
|
|
||||||
header authCookieName $ Rpxnow.identifier ident
|
header authCookieName $ Rpxnow.identifier ident
|
||||||
header authDisplayName $ getDisplayName ident
|
header authDisplayName $ getDisplayName ident
|
||||||
redirectToDest RedirectTemporary dest
|
redirectToDest RedirectTemporary dest
|
||||||
|
|||||||
@ -32,7 +32,7 @@ library
|
|||||||
convertible-text >= 0.2.0 && < 0.3,
|
convertible-text >= 0.2.0 && < 0.3,
|
||||||
template-haskell,
|
template-haskell,
|
||||||
web-routes >= 0.22 && < 0.23,
|
web-routes >= 0.22 && < 0.23,
|
||||||
web-routes-quasi >= 0.0 && < 0.1,
|
web-routes-quasi >= 0.1 && < 0.2,
|
||||||
hamlet >= 0.0.1 && < 0.1
|
hamlet >= 0.0.1 && < 0.1
|
||||||
if flag(transformers_02)
|
if flag(transformers_02)
|
||||||
build-depends: transformers >= 0.2 && < 0.3
|
build-depends: transformers >= 0.2 && < 0.3
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user