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
This commit is contained in:
parent
0d4d377c8e
commit
db89e940a5
@ -4,6 +4,8 @@
|
|||||||
module Web.Authenticate.Facebook
|
module Web.Authenticate.Facebook
|
||||||
( Facebook (..)
|
( Facebook (..)
|
||||||
, AccessToken (..)
|
, AccessToken (..)
|
||||||
|
, getForwardUrlParams
|
||||||
|
, getForwardUrlWithState
|
||||||
, getForwardUrl
|
, getForwardUrl
|
||||||
, getAccessToken
|
, getAccessToken
|
||||||
, getGraphData
|
, getGraphData
|
||||||
@ -27,6 +29,7 @@ import Blaze.ByteString.Builder.Char.Utf8 (fromText)
|
|||||||
import Network.HTTP.Types (renderQueryText)
|
import Network.HTTP.Types (renderQueryText)
|
||||||
import Data.Monoid (mappend)
|
import Data.Monoid (mappend)
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
|
import Control.Arrow ((***))
|
||||||
|
|
||||||
data Facebook = Facebook
|
data Facebook = Facebook
|
||||||
{ facebookClientId :: Text
|
{ facebookClientId :: Text
|
||||||
@ -38,18 +41,27 @@ data Facebook = Facebook
|
|||||||
newtype AccessToken = AccessToken { unAccessToken :: Text }
|
newtype AccessToken = AccessToken { unAccessToken :: Text }
|
||||||
deriving (Show, Eq, Read, Ord, Data, Typeable)
|
deriving (Show, Eq, Read, Ord, Data, Typeable)
|
||||||
|
|
||||||
getForwardUrl :: Facebook -> [Text] -> Text
|
getForwardUrlParams :: Facebook -> [(Text, Text)] -> Text
|
||||||
getForwardUrl fb perms =
|
getForwardUrlParams fb params =
|
||||||
TE.decodeUtf8 $ toByteString $
|
TE.decodeUtf8 $ toByteString $
|
||||||
copyByteString "https://graph.facebook.com/oauth/authorize"
|
copyByteString "https://graph.facebook.com/oauth/authorize"
|
||||||
`mappend`
|
`mappend`
|
||||||
renderQueryText True
|
renderQueryText True
|
||||||
( ("client_id", Just $ facebookClientId fb)
|
([ ("client_id", Just $ facebookClientId fb)
|
||||||
: ("redirect_uri", Just $ facebookRedirectUri fb)
|
, ("redirect_uri", Just $ facebookRedirectUri fb)
|
||||||
: if null perms
|
] ++ map (id *** Just) params)
|
||||||
then []
|
|
||||||
else [("scope", Just $ T.intercalate "," perms)])
|
|
||||||
|
|
||||||
|
-- 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 :: Facebook -> Text -> ByteString
|
||||||
accessTokenUrl fb code =
|
accessTokenUrl fb code =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user