Skip to content

Instantly share code, notes, and snippets.

@tungd
Created May 13, 2017 11:07
Show Gist options
  • Save tungd/c3acfbd10e543a872c3caabe37245f3f to your computer and use it in GitHub Desktop.
Save tungd/c3acfbd10e543a872c3caabe37245f3f to your computer and use it in GitHub Desktop.
#!/usr/bin/env stack
-- stack --resolver lts-8.13 --install-ghc runghc --package scotty --package fb
-- --package text --package http-client --package http-client-tls
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Resource
import qualified Data.Text.Lazy as T
import Facebook
import Network.HTTP.Client
import Network.HTTP.Client.TLS
import Web.Scotty
main = do
mgr <- newManager tlsManagerSettings
scotty 3000 $ do
get "/" $ do
url <- runResourceT $ runFacebookT credentials mgr $ do
getUserAccessTokenStep1 callbackUrl scopes
redirect $ T.fromStrict url
get "/auth/facebook/callback" $ do
code <- param "code"
token <- lift $ runResourceT $ runFacebookT credentials mgr $ do
getUserAccessTokenStep2 callbackUrl [("code", code)]
redirect "/"
callbackUrl = "http://localhost:3000/auth/facebook/callback"
credentials = Credentials
{ appName = "xxx"
, appId = "xxx"
, appSecret = "xxx" }
scopes =
[ "public_profile"
, "email"
, "manage_pages"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment