yesod-auth-fb: Authentication backend for Yesod using Facebook.

[ bsd3, library, web ] [ Propose Tags ] [ Report a vulnerability ]

This package allows you to use Yesod's authentication framework with Facebook as your backend. That is, your site's users will log in to your site through Facebook. Your application need to be registered on Facebook.

This package works with both the server-side authentication flow (https://developers.facebook.com/docs/authentication/server-side/) via the Yesod.Auth.Facebook.ServerSide module and the client-side authentication (https://developers.facebook.com/docs/authentication/client-side/) via the Yesod.Auth.Facebook.ClientSide module. It's up to you to decide which one to use. The server-side code is older and as such has been through a lot more testing than the client-side code. Also, for now only the server-side code is able to work with other authentication plugins. The client-side code, however, allows you to use some features that are available only to the Facebook JS SDK (such as automatically logging your users in, see https://developers.facebook.com/blog/post/2012/05/08/how-to--improve-the-experience-for-returning-users/).


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0, 0.10, 0.10.1, 0.10.2, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.1, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.3, 1.3.1, 1.3.2, 1.4, 1.5, 1.5.1, 1.6, 1.6.1, 1.6.2, 1.6.2.1, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.7, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1
Change log CHANGELOG.md
Dependencies aeson (>=0.6), base (>=4.11 && <5), bytestring (>=0.9), conduit (>=1.3.0), fb (>=2.1.1), http-conduit (>=1.9), resourcet (>=1.2.0), shakespeare (>=2.0), text (>=0.7), time (>=1.0), transformers (>=0.1.3), unliftio, wai, yesod-auth (>=1.6.1), yesod-core (>=1.6.1), yesod-fb (>=0.6.1) [details]
License BSD-3-Clause
Author Felipe Lessa, Michael Snoyman
Maintainer Sibi <sibi@psibi.in>
Category Web
Home page https://github.com/psibi/yesod-auth-fb
Source repo head: git clone git@github.com:psibi/yesod-auth-fb.git
Uploaded by psibi at 2020-03-14T17:21:15Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 26422 total (85 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-03-14 [all 1 reports]

Readme for yesod-auth-fb-1.10.1

[back to package description]

yesod-auth-fb

Build Status Hackage StackageNightly StackageLTS

Authentication backend for Yesod using Facebook

Demo

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 =
  App

mkYesod
  "App"
  [parseRoutes|
/ 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
  defaultLayout
    [whamlet|
            <p>Your current auth ID: #{show maid}
            $maybe _ <- maid
                <p>
                    <a href=@{AuthR LogoutR}>Logout
                    <a href=@{AuthR facebookLogout}>Facebook logout
            $nothing
                <p>
                    <a href=@{AuthR LoginR}>Go to the login page
        |]

main :: IO ()
main = warp 3000 App