https://github.com/psibi/yesod-auth-fb
https://github.com/psibi/yesod-auth-fb
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/psibi/yesod-auth-fb
- Owner: psibi
- License: bsd-3-clause
- Created: 2017-03-11T07:40:24.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-03-22T15:13:24.000Z (about 6 years ago)
- Last Synced: 2025-04-09T18:57:10.514Z (about 1 year ago)
- Language: Haskell
- Size: 155 KB
- Stars: 1
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
yesod-auth-fb
---------------
[](https://dev.azure.com/psibi2000/Haskell%20Projects/_build/latest?definitionId=18&branchName=master)
[](https://hackage.haskell.org/package/yesod-auth-fb)
[](http://stackage.org/nightly/package/yesod-auth-fb)
[](http://stackage.org/lts/package/yesod-auth-fb)
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|
Your current auth ID: #{show maid}
$maybe _ <- maid
Logout
Facebook logout
$nothing
main :: IO ()
main = warp 3000 App
```