-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathFacebook.hs
57 lines (50 loc) · 1.75 KB
/
Facebook.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE QuasiQuotes #-}
-- | [Facebook Login](http://developers.facebook.com/docs/facebook-login/)
module Network.OAuth2.Provider.Facebook where
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Except (ExceptT (..))
import Data.Aeson (FromJSON)
import Data.ByteString.Lazy.Char8 qualified as BSL
import Data.Map.Strict qualified as Map
import Data.Set qualified as Set
import Data.Text.Lazy (Text)
import GHC.Generics
import Network.HTTP.Conduit (Manager)
import Network.OAuth.OAuth2
import Network.OAuth2.Experiment
import Network.OAuth2.Provider
import URI.ByteString.QQ
sampleFacebookAuthorizationCodeApp :: AuthorizationCodeApplication
sampleFacebookAuthorizationCodeApp =
AuthorizationCodeApplication
{ acClientId = ""
, acClientSecret = ""
, acScope = Set.fromList ["user_about_me", "email"]
, acAuthorizeRequestExtraParams = Map.empty
, acAuthorizeState = "CHANGE_ME"
, acRedirectUri = [uri|http://localhost|]
, acName = "sample-facebook-authorization-code-app"
, acTokenRequestAuthenticationMethod = ClientSecretPost
}
fetchUserInfo ::
(MonadIO m, HasUserInfoRequest a, FromJSON b) =>
IdpApplication i a ->
Manager ->
AccessToken ->
ExceptT BSL.ByteString m b
fetchUserInfo = conduitUserInfoRequest
defaultFacebookIdp :: Idp Facebook
defaultFacebookIdp =
Idp
{ idpUserInfoEndpoint = [uri|https://graph.facebook.com/me?fields=id,name,email|]
, idpAuthorizeEndpoint = [uri|https://www.facebook.com/dialog/oauth|]
, idpTokenEndpoint = [uri|https://graph.facebook.com/v2.3/oauth/access_token|]
, idpDeviceAuthorizationEndpoint = Nothing
}
data FacebookUser = FacebookUser
{ id :: Text
, name :: Text
, email :: Text
}
deriving (Show, Generic)
instance FromJSON FacebookUser