{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module Network.OAuth2.Provider.Facebook where
import Data.Aeson
import Data.Map.Strict qualified as Map
import Data.Set qualified as Set
import Data.Text.Lazy (Text)
import GHC.Generics
import Network.OAuth.OAuth2
import Network.OAuth2.Experiment
import URI.ByteString.QQ
data Facebook = Facebook deriving (Facebook -> Facebook -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Facebook -> Facebook -> Bool
$c/= :: Facebook -> Facebook -> Bool
== :: Facebook -> Facebook -> Bool
$c== :: Facebook -> Facebook -> Bool
Eq, Int -> Facebook -> ShowS
[Facebook] -> ShowS
Facebook -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Facebook] -> ShowS
$cshowList :: [Facebook] -> ShowS
show :: Facebook -> String
$cshow :: Facebook -> String
showsPrec :: Int -> Facebook -> ShowS
$cshowsPrec :: Int -> Facebook -> ShowS
Show)
type instance IdpUserInfo Facebook = FacebookUser
defaultFacebookApp :: IdpApplication 'AuthorizationCode Facebook
defaultFacebookApp :: IdpApplication 'AuthorizationCode Facebook
defaultFacebookApp =
AuthorizationCodeIdpApplication
{ $sel:idpAppClientId:AuthorizationCodeIdpApplication :: ClientId
idpAppClientId = ClientId
"",
$sel:idpAppClientSecret:AuthorizationCodeIdpApplication :: ClientSecret
idpAppClientSecret = ClientSecret
"",
$sel:idpAppScope:AuthorizationCodeIdpApplication :: Set Scope
idpAppScope = forall a. Ord a => [a] -> Set a
Set.fromList [Scope
"user_about_me", Scope
"email"],
$sel:idpAppAuthorizeExtraParams:AuthorizationCodeIdpApplication :: Map Text Text
idpAppAuthorizeExtraParams = forall k a. Map k a
Map.empty,
$sel:idpAppAuthorizeState:AuthorizationCodeIdpApplication :: AuthorizeState
idpAppAuthorizeState = AuthorizeState
"CHANGE_ME",
$sel:idpAppRedirectUri:AuthorizationCodeIdpApplication :: URI
idpAppRedirectUri = [uri|http://localhost|],
$sel:idpAppName:AuthorizationCodeIdpApplication :: Text
idpAppName = Text
"default-facebook-App",
$sel:idpAppTokenRequestAuthenticationMethod:AuthorizationCodeIdpApplication :: ClientAuthenticationMethod
idpAppTokenRequestAuthenticationMethod = ClientAuthenticationMethod
ClientSecretPost,
$sel:idp:AuthorizationCodeIdpApplication :: Idp Facebook
idp = Idp Facebook
defaultFacebookIdp
}
defaultFacebookIdp :: Idp Facebook
defaultFacebookIdp :: Idp Facebook
defaultFacebookIdp =
Idp
{ $sel:idpFetchUserInfo:Idp :: forall (m :: * -> *).
(FromJSON (IdpUserInfo Facebook), MonadIO m) =>
Manager
-> AccessToken
-> URI
-> ExceptT ByteString m (IdpUserInfo Facebook)
idpFetchUserInfo = forall a (m :: * -> *).
(FromJSON a, MonadIO m) =>
Manager -> AccessToken -> URI -> ExceptT ByteString m a
authGetJSON @(IdpUserInfo Facebook),
$sel:idpUserInfoEndpoint:Idp :: URI
idpUserInfoEndpoint = [uri|https://graph.facebook.com/me?fields=id,name,email|],
$sel:idpAuthorizeEndpoint:Idp :: URI
idpAuthorizeEndpoint = [uri|https://www.facebook.com/dialog/oauth|],
$sel:idpTokenEndpoint:Idp :: URI
idpTokenEndpoint = [uri|https://graph.facebook.com/v2.3/oauth/access_token|]
}
data FacebookUser = FacebookUser
{ FacebookUser -> Text
id :: Text,
FacebookUser -> Text
name :: Text,
FacebookUser -> Text
email :: Text
}
deriving (Int -> FacebookUser -> ShowS
[FacebookUser] -> ShowS
FacebookUser -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FacebookUser] -> ShowS
$cshowList :: [FacebookUser] -> ShowS
show :: FacebookUser -> String
$cshow :: FacebookUser -> String
showsPrec :: Int -> FacebookUser -> ShowS
$cshowsPrec :: Int -> FacebookUser -> ShowS
Show, forall x. Rep FacebookUser x -> FacebookUser
forall x. FacebookUser -> Rep FacebookUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FacebookUser x -> FacebookUser
$cfrom :: forall x. FacebookUser -> Rep FacebookUser x
Generic)
instance FromJSON FacebookUser