authBrowserId'
This commit is contained in:
parent
40e83beae3
commit
b00fd948bd
@ -3,6 +3,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
module Yesod.Auth.BrowserId
|
module Yesod.Auth.BrowserId
|
||||||
( authBrowserId
|
( authBrowserId
|
||||||
|
, authBrowserId'
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Yesod.Auth
|
import Yesod.Auth
|
||||||
@ -11,6 +12,8 @@ import Data.Text (Text)
|
|||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
import Text.Hamlet (hamlet)
|
import Text.Hamlet (hamlet)
|
||||||
import Control.Monad.IO.Class (liftIO)
|
import Control.Monad.IO.Class (liftIO)
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
#include "qq.h"
|
#include "qq.h"
|
||||||
|
|
||||||
@ -46,3 +49,33 @@ authBrowserId audience = AuthPlugin
|
|||||||
<img src="https://browserid.org/i/sign_in_green.png">
|
<img src="https://browserid.org/i/sign_in_green.png">
|
||||||
|]
|
|]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authBrowserId' :: YesodAuth m => AuthPlugin m
|
||||||
|
authBrowserId' = AuthPlugin
|
||||||
|
{ apName = pid
|
||||||
|
, apDispatch = \m ps ->
|
||||||
|
case (m, ps) of
|
||||||
|
("GET", [assertion]) -> do
|
||||||
|
tm <- getRouteToMaster
|
||||||
|
r <- getUrlRender
|
||||||
|
let audience = T.takeWhile (/= '/') $ stripScheme $ r $ tm LoginR
|
||||||
|
memail <- liftIO $ checkAssertion audience assertion
|
||||||
|
case memail of
|
||||||
|
Nothing -> error "Invalid assertion"
|
||||||
|
Just email -> setCreds True Creds
|
||||||
|
{ credsPlugin = pid
|
||||||
|
, credsIdent = email
|
||||||
|
, credsExtra = []
|
||||||
|
}
|
||||||
|
(_, []) -> badMethod
|
||||||
|
_ -> notFound
|
||||||
|
, apLogin = \toMaster -> do
|
||||||
|
addScriptRemote browserIdJs
|
||||||
|
addHamlet [QQ(hamlet)|
|
||||||
|
<p>
|
||||||
|
<a href="javascript:navigator.id.getVerifiedEmail(function(a){if(a)document.location='@{toMaster complete}/'+a});">
|
||||||
|
<img src="https://browserid.org/i/sign_in_green.png">
|
||||||
|
|]
|
||||||
|
}
|
||||||
|
where
|
||||||
|
stripScheme t = fromMaybe t $ T.stripPrefix "//" $ snd $ T.breakOn "//" t
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import Yesod.Form
|
|||||||
import Network.Wai.Handler.Warp (run)
|
import Network.Wai.Handler.Warp (run)
|
||||||
|
|
||||||
data BID = BID
|
data BID = BID
|
||||||
type Handler = GHandler BID BID
|
|
||||||
|
|
||||||
mkYesod "BID" [parseRoutes|
|
mkYesod "BID" [parseRoutes|
|
||||||
/ RootR GET
|
/ RootR GET
|
||||||
@ -39,7 +38,7 @@ instance YesodAuth BID where
|
|||||||
loginDest _ = AfterLoginR
|
loginDest _ = AfterLoginR
|
||||||
logoutDest _ = AuthR LoginR
|
logoutDest _ = AuthR LoginR
|
||||||
getAuthId = return . Just . credsIdent
|
getAuthId = return . Just . credsIdent
|
||||||
authPlugins = [authBrowserId "localhost:3000"]
|
authPlugins = [authBrowserId']
|
||||||
|
|
||||||
instance RenderMessage BID FormMessage where
|
instance RenderMessage BID FormMessage where
|
||||||
renderMessage _ _ = defaultFormMessage
|
renderMessage _ _ = defaultFormMessage
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-auth
|
name: yesod-auth
|
||||||
version: 0.7.2
|
version: 0.7.3
|
||||||
license: BSD3
|
license: BSD3
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman, Patrick Brisbin
|
author: Michael Snoyman, Patrick Brisbin
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user