Authentication backend for Yesod using Facebook.

Version on this page:1.9.1
LTS Haskell 16.31:1.10.1
Stackage Nightly 2022-02-07:1.10.1
Latest on Hackage:1.10.1

See all snapshots yesod-auth-fb appears in

BSD-3-Clause licensed by Felipe Lessa, Michael Snoyman
Maintained by Sibi
This version can be pinned in stack with:yesod-auth-fb-1.9.1@sha256:09258041da955c5fd5df91ef9ee84383530fb187183bff8a1648445d11d81e48,2617

Module documentation for 1.9.1


Build Status

Authentication backend for Yesod using Facebook


Sample code showing Facebook authentication in action:

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}

import Data.Text (Text)
import Yesod
import Yesod.Auth
import Yesod.Facebook
import Yesod.Auth.Facebook.ServerSide
import Facebook (Credentials(..))

fbclientId :: Text
fbclientId = "sample_fb_client_id"

fbclientSecret :: Text
fbclientSecret = "sample_fb_secret"

data App =

/ HomeR GET
/auth AuthR Auth getAuth

instance Yesod App where
  approot = ApprootStatic "http://localhost:3000"

instance YesodFacebook App where
  fbCredentials _ = Credentials "yesod" fbclientId fbclientSecret

instance YesodAuth App where
  type AuthId App = Text
  getAuthId = return . Just . credsIdent
  loginDest _ = HomeR
  logoutDest _ = HomeR
  authPlugins _ = [authFacebook ["user_about_me", "email"]]
  -- The default maybeAuthId assumes a Persistent database. We're going for a
  -- simpler AuthId, so we'll just do a direct lookup in the session.
  maybeAuthId = lookupSession "_ID"

instance RenderMessage App FormMessage where
  renderMessage _ _ = defaultFormMessage

getHomeR :: Handler Html
getHomeR = do
  maid <- maybeAuthId
            <p>Your current auth ID: #{show maid}
            $maybe _ <- maid
                    <a href=@{AuthR LogoutR}>Logout
                    <a href=@{AuthR facebookLogout}>Facebook logout
                    <a href=@{AuthR LoginR}>Go to the login page

main :: IO ()
main = warp 3000 App


Version 1.9.1

  • Only pass code query param to getUserAccessTokenStep2

Version 1.9.0

  • Supports conduit >= 1.3.0
  • Documentation updated to include demo code.
  • Supports latest yesod >= 1.6.0.
  • Remove dependency on lifted-base and related ecosystem.