From db89e940a5ee5a71761a5d6106e40b98a4717dcb Mon Sep 17 00:00:00 2001 From: Rian Hunter Date: Tue, 29 Nov 2011 15:31:58 -0800 Subject: [PATCH 1/4] Add new functions, getForwardUrlWithState that takes an extra state query arg for authenticating with facebook, also getForwardUrlParams that takes arbitrary query params for future-proofing --- Web/Authenticate/Facebook.hs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Web/Authenticate/Facebook.hs b/Web/Authenticate/Facebook.hs index 97ace9ec..188853b6 100644 --- a/Web/Authenticate/Facebook.hs +++ b/Web/Authenticate/Facebook.hs @@ -4,6 +4,8 @@ module Web.Authenticate.Facebook ( Facebook (..) , AccessToken (..) + , getForwardUrlParams + , getForwardUrlWithState , getForwardUrl , getAccessToken , getGraphData @@ -27,6 +29,7 @@ import Blaze.ByteString.Builder.Char.Utf8 (fromText) import Network.HTTP.Types (renderQueryText) import Data.Monoid (mappend) import Data.ByteString (ByteString) +import Control.Arrow ((***)) data Facebook = Facebook { facebookClientId :: Text @@ -38,18 +41,27 @@ data Facebook = Facebook newtype AccessToken = AccessToken { unAccessToken :: Text } deriving (Show, Eq, Read, Ord, Data, Typeable) -getForwardUrl :: Facebook -> [Text] -> Text -getForwardUrl fb perms = +getForwardUrlParams :: Facebook -> [(Text, Text)] -> Text +getForwardUrlParams fb params = TE.decodeUtf8 $ toByteString $ copyByteString "https://graph.facebook.com/oauth/authorize" `mappend` renderQueryText True - ( ("client_id", Just $ facebookClientId fb) - : ("redirect_uri", Just $ facebookRedirectUri fb) - : if null perms - then [] - else [("scope", Just $ T.intercalate "," perms)]) + ([ ("client_id", Just $ facebookClientId fb) + , ("redirect_uri", Just $ facebookRedirectUri fb) + ] ++ map (id *** Just) params) +-- Internal function used to simplify getForwardUrl & getForwardUrlWithState +getForwardUrlWithExtra_ :: Facebook -> [Text] -> [(Text, Text)] -> Text +getForwardUrlWithExtra_ fb perms extra = getForwardUrlParams fb $ (if null perms + then [] + else [("scope", T.intercalate "," perms)]) ++ extra + +getForwardUrlWithState :: Facebook -> [Text] -> Text -> Text +getForwardUrlWithState fb perms state = getForwardUrlWithExtra_ fb perms [("state", state)] + +getForwardUrl :: Facebook -> [Text] -> Text +getForwardUrl fb perms = getForwardUrlWithExtra_ fb perms [] accessTokenUrl :: Facebook -> Text -> ByteString accessTokenUrl fb code = From fd129fce1a4a093ed6ddd96cdd3a30d6f258ad74 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 1 Dec 2011 12:43:26 +0200 Subject: [PATCH 2/4] aeson 0.4 --- Web/Authenticate/BrowserId.hs | 5 +++++ Web/Authenticate/Rpxnow.hs | 4 ++++ authenticate.cabal | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Web/Authenticate/BrowserId.hs b/Web/Authenticate/BrowserId.hs index 8f9cb5f9..9133e0c2 100644 --- a/Web/Authenticate/BrowserId.hs +++ b/Web/Authenticate/BrowserId.hs @@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE CPP #-} module Web.Authenticate.BrowserId ( browserIdJs , checkAssertion @@ -8,7 +9,11 @@ import Data.Text (Text) import Network.HTTP.Enumerator (parseUrl, responseBody, httpLbs, withManager, method, urlEncodedBody) import Data.Aeson (json, Value (Object, String)) import Data.Attoparsec.Lazy (parse, maybeResult) +#if MIN_VERSION_aeson(0, 4, 0) +import qualified Data.HashMap.Lazy as Map +#else import qualified Data.Map as Map +#endif import Data.Text.Encoding (encodeUtf8) -- | Location of the Javascript file hosted by browserid.org diff --git a/Web/Authenticate/Rpxnow.hs b/Web/Authenticate/Rpxnow.hs index 6df5f9d3..f856f036 100644 --- a/Web/Authenticate/Rpxnow.hs +++ b/Web/Authenticate/Rpxnow.hs @@ -38,7 +38,11 @@ import Data.Attoparsec.Lazy (parse) import qualified Data.Attoparsec.Lazy as AT import Data.Text (Text) import qualified Data.Aeson.Types +#if MIN_VERSION_aeson(0, 4, 0) +import qualified Data.HashMap.Lazy as Map +#else import qualified Data.Map as Map +#endif import Control.Applicative ((<$>), (<*>)) -- | Information received from Rpxnow after a valid login. diff --git a/authenticate.cabal b/authenticate.cabal index 1b93b29c..be5dda31 100644 --- a/authenticate.cabal +++ b/authenticate.cabal @@ -1,5 +1,5 @@ name: authenticate -version: 0.10.3 +version: 0.10.3.1 license: BSD3 license-file: LICENSE author: Michael Snoyman, Hiromi Ishii, Arash Rouhani @@ -36,6 +36,7 @@ library attoparsec >= 0.9, tls >= 0.7 && < 0.9, containers, + unordered-containers, process >= 1.0.1.1 && < 1.2 exposed-modules: Web.Authenticate.Rpxnow, Web.Authenticate.OpenId, From 717d4deda5ae881602a4b6411289720bea441041 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Fri, 2 Dec 2011 11:36:43 +0200 Subject: [PATCH 3/4] Avoid ++ --- Web/Authenticate/Facebook.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Web/Authenticate/Facebook.hs b/Web/Authenticate/Facebook.hs index 188853b6..13b68238 100644 --- a/Web/Authenticate/Facebook.hs +++ b/Web/Authenticate/Facebook.hs @@ -47,15 +47,15 @@ getForwardUrlParams fb params = copyByteString "https://graph.facebook.com/oauth/authorize" `mappend` renderQueryText True - ([ ("client_id", Just $ facebookClientId fb) - , ("redirect_uri", Just $ facebookRedirectUri fb) - ] ++ map (id *** Just) params) + ( ("client_id", Just $ facebookClientId fb) + : ("redirect_uri", Just $ facebookRedirectUri fb) + : map (id *** Just) params) -- Internal function used to simplify getForwardUrl & getForwardUrlWithState getForwardUrlWithExtra_ :: Facebook -> [Text] -> [(Text, Text)] -> Text getForwardUrlWithExtra_ fb perms extra = getForwardUrlParams fb $ (if null perms - then [] - else [("scope", T.intercalate "," perms)]) ++ extra + then id + else (("scope", T.intercalate "," perms):)) extra getForwardUrlWithState :: Facebook -> [Text] -> Text -> Text getForwardUrlWithState fb perms state = getForwardUrlWithExtra_ fb perms [("state", state)] From 2df6650172ff5aa805248d5c95fdc769dccf2c7b Mon Sep 17 00:00:00 2001 From: Felipe Lessa Date: Mon, 19 Dec 2011 09:49:11 -0200 Subject: [PATCH 4/4] Add getLogoutUrl to Facebook. --- Web/Authenticate/Facebook.hs | 10 ++++++++++ authenticate.cabal | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Web/Authenticate/Facebook.hs b/Web/Authenticate/Facebook.hs index 13b68238..bb9fd4a9 100644 --- a/Web/Authenticate/Facebook.hs +++ b/Web/Authenticate/Facebook.hs @@ -10,6 +10,7 @@ module Web.Authenticate.Facebook , getAccessToken , getGraphData , getGraphData_ + , getLogoutUrl ) where import Network.HTTP.Enumerator @@ -103,3 +104,12 @@ getGraphData_ a b = getGraphData a b >>= either (throwIO . InvalidJsonException) data InvalidJsonException = InvalidJsonException String deriving (Show, Typeable) instance Exception InvalidJsonException + +-- | Logs out the user from their Facebook session. +getLogoutUrl :: AccessToken + -> Text -- ^ URL the user should be directed to in your site domain. + -> Text -- ^ Logout URL in @https://www.facebook.com/@. +getLogoutUrl (AccessToken s) next = + TE.decodeUtf8 $ toByteString $ + copyByteString "https://www.facebook.com/logout.php" + `mappend` renderQueryText True [("next", Just next), ("access_token", Just s)] diff --git a/authenticate.cabal b/authenticate.cabal index be5dda31..882ecee2 100644 --- a/authenticate.cabal +++ b/authenticate.cabal @@ -1,5 +1,5 @@ name: authenticate -version: 0.10.3.1 +version: 0.10.4 license: BSD3 license-file: LICENSE author: Michael Snoyman, Hiromi Ishii, Arash Rouhani