OAuth2 authentication for yesod
Go to file
pat brisbin a4f9dc91f5 Merge pull request #34 from thoughtbot/pb-fixes
Prep for release after Eve Online merge
2015-07-22 12:03:19 -04:00
Yesod/Auth Add charId to credsExtra 2015-07-22 12:02:15 -04:00
.gitignore misc gitignore updates 2014-09-20 23:53:46 -07:00
.travis.yml Add a better .travis.yml 2015-04-13 11:19:16 -04:00
LICENSE Initial import 2013-07-14 11:11:44 +02:00
README.md Update README for new usage 2014-09-22 15:02:28 -04:00
Setup.lhs Initial import 2013-07-14 11:11:44 +02:00
yesod-auth-oauth2.cabal reverted version bump, removed dependency on time 2015-06-28 17:17:21 +02:00

Yesod.Auth.OAuth2

OAuth2 AuthPlugins for Yesod.

Basic Usage

To use one of the supported providers:

import Yesod.Auth
import Yesod.Auth.OAuth2.Github

instance YesodAuth App where
    -- ...

    authPlugins _ = [oauth2Github clientId clientSecret]

clientId :: Text
clientId = "..."

clientSecret :: Text
clientSecret = "..."

Advanced Usage

To use any other provider:

import Yesod.Auth
import Yesod.Auth.OAuth2

instance YesodAuth App where
    -- ...

    authPlugins _ = [myPlugin]

myPlugin :: AuthPlugin m
myPlugin = authOAuth2 "mysite"
    (OAuth2
        { oauthClientId            = "..."
        , oauthClientSecret        = "..."
        , oauthOAuthorizeEndpoint  = "https://mysite.com/oauth/authorize"
        , oauthAccessTokenEndpoint = "https://mysite.com/oauth/token"
        , oauthCallback            = Nothing
        })
    makeCredentials

makeCredentials :: Manager -> AccessToken -> IO (Creds m)
makeCredentials manager token = do
    result <- authGetJSON manager token "https://mysite.com/api/me.json"
    return $ -- Parse the JSON into (Creds m)

If you write one of these, please consider opening a Pull Request