yesod-auth 1.0.1 → 1.0.2
raw patch · 3 files changed
+68/−9 lines, 3 filesdep +blaze-markupdep ~authenticatedep ~blaze-htmlPVP ok
version bump matches the API change (PVP)
Dependencies added: blaze-markup
Dependency ranges changed: authenticate, blaze-html
API changes (from Hackage documentation)
+ Yesod.Auth.OpenId: claimedKey :: Text
+ Yesod.Auth.OpenId: credsIdentClaimed :: Creds m -> Text
Files
- Yesod/Auth/GoogleEmail.hs +8/−2
- Yesod/Auth/OpenId.hs +46/−4
- yesod-auth.cabal +14/−3
Yesod/Auth/GoogleEmail.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP #-} -- | Use an email address as an identifier via Google's OpenID login system. -- -- This backend will not use the OpenID identifier at all. It only uses OpenID@@ -20,7 +21,11 @@ import Yesod.Handler import Yesod.Widget (whamlet) import Yesod.Request+#if MIN_VERSION_blaze_html(0, 5, 0)+import Text.Blaze.Html (toHtml)+#else import Text.Blaze (toHtml)+#endif import Data.Text (Text) import qualified Yesod.Auth.Message as Msg import qualified Data.Text as T@@ -72,12 +77,13 @@ completeHelper :: YesodAuth m => [(Text, Text)] -> GHandler Auth m () completeHelper gets' = do master <- getYesod- eres <- lift $ try $ OpenId.authenticate gets' (authHttpManager master)+ eres <- lift $ try $ OpenId.authenticateClaimed gets' (authHttpManager master) toMaster <- getRouteToMaster let onFailure err = do setMessage $ toHtml $ show (err :: SomeException) redirect $ toMaster LoginR- let onSuccess (OpenId.Identifier ident, _) = do+ let onSuccess oir = do+ let OpenId.Identifier ident = OpenId.oirOpLocal oir memail <- lookupGetParam "openid.ext1.value.email" case (memail, "https://www.google.com/accounts/o8/id" `T.isPrefixOf` ident) of (Just email, True) -> setCreds True $ Creds "openid" email []
Yesod/Auth/OpenId.hs view
@@ -1,9 +1,12 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP #-} module Yesod.Auth.OpenId ( authOpenId , authOpenIdExtended , forwardUrl+ , claimedKey+ , credsIdentClaimed ) where import Yesod.Auth@@ -14,10 +17,15 @@ import Yesod.Widget (toWidget, whamlet) import Yesod.Request import Text.Cassius (cassius)+#if MIN_VERSION_blaze_html(0, 5, 0)+import Text.Blaze.Html (toHtml)+#else import Text.Blaze (toHtml)-import Data.Text (Text)+#endif+import Data.Text (Text, isPrefixOf) import qualified Yesod.Auth.Message as Msg import Control.Exception.Lifted (SomeException, try)+import Data.Maybe (fromMaybe) forwardUrl :: AuthRoute forwardUrl = PluginR "openid" ["forward"]@@ -80,11 +88,45 @@ completeHelper :: YesodAuth m => [(Text, Text)] -> GHandler Auth m () completeHelper gets' = do master <- getYesod- eres <- lift $ try $ OpenId.authenticate gets' (authHttpManager master)+ eres <- lift $ try $ OpenId.authenticateClaimed gets' (authHttpManager master) toMaster <- getRouteToMaster let onFailure err = do setMessage $ toHtml $ show (err :: SomeException) redirect $ toMaster LoginR- let onSuccess (OpenId.Identifier ident, _) =- setCreds True $ Creds "openid" ident gets'+ let onSuccess oir = do+ let claimed =+ case OpenId.oirClaimed oir of+ Nothing -> id+ Just (OpenId.Identifier i') -> ((claimedKey, i'):)+ gets'' = claimed $ filter (\(k, _) -> not $ "__" `isPrefixOf` k) gets'+ i = OpenId.identifier $ OpenId.oirOpLocal oir+ setCreds True $ Creds "openid" i gets'' either onFailure onSuccess eres++-- | The main identifier provided by the OpenID authentication plugin is the+-- \"OP-local identifier\". There is also sometimes a \"claimed\" identifier+-- available.+--+-- In the 'credsExtra' field of the 'Creds' datatype, you can lookup this key+-- to find the claimed identifier, if available.+--+-- > let finalID = fromMaybe (credsIdent creds)+-- > $ lookup claimedKey (credsExtra creds)+--+-- Since 1.0.2+claimedKey :: Text+claimedKey = "__CLAIMED"++-- | A helper function which will get the claimed identifier, if available, falling back to the OP local identifier.+--+-- See 'claimedKey'.+--+-- Since 1.0.2+credsIdentClaimed :: Creds m -> Text++-- Prevent other backends from overloading the __CLAIMED value, which could+-- possibly open us to security holes.+credsIdentClaimed c | credsPlugin c /= "openid" = credsIdent c++credsIdentClaimed c = fromMaybe (credsIdent c)+ $ lookup claimedKey (credsExtra c)
yesod-auth.cabal view
@@ -1,5 +1,5 @@ name: yesod-auth-version: 1.0.1+version: 1.0.2 license: MIT license-file: LICENSE author: Michael Snoyman, Patrick Brisbin@@ -14,9 +14,13 @@ flag ghc7 +flag blaze_html_0_5+ description: use blaze-html 0.5 and blaze-markup 0.5+ default: False+ library build-depends: base >= 4 && < 5- , authenticate >= 1.2 && < 1.3+ , authenticate >= 1.2.1 && < 1.3 , bytestring >= 0.9.1.4 && < 0.10 , yesod-core >= 1.0 && < 1.1 , wai >= 1.2 && < 1.3@@ -25,7 +29,6 @@ , random >= 1.0.0.2 && < 1.1 , text >= 0.7 && < 0.12 , mime-mail >= 0.3 && < 0.5- , blaze-html >= 0.4.1.3 && < 0.5 , yesod-persistent >= 1.0 && < 1.1 , hamlet >= 1.0 && < 1.1 , shakespeare-css >= 1.0 && < 1.1@@ -41,6 +44,14 @@ , aeson >= 0.5 , pwstore-fast >= 2.2 && < 3 , lifted-base >= 0.1 && < 0.2++ if flag(blaze_html_0_5)+ build-depends:+ blaze-html >= 0.5 && < 0.6+ , blaze-markup >= 0.5.1 && < 0.6+ else+ build-depends:+ blaze-html >= 0.4 && < 0.5 exposed-modules: Yesod.Auth Yesod.Auth.BrowserId