OAuth2 authentication for yesod
Go to file
Florian Gilcher 81ece8072f Make Github name optional
The github API returns no name field if the user has given none (and
only goes by their user handle). For that reason, make the name field
optional.
2014-09-18 11:40:12 +02:00
Yesod/Auth Make Github name optional 2014-09-18 11:40:12 +02:00
.gitignore Initial import 2013-07-14 11:11:44 +02:00
LICENSE Initial import 2013-07-14 11:11:44 +02:00
README.md Add content to README 2014-02-20 15:47:05 -05:00
Setup.lhs Initial import 2013-07-14 11:11:44 +02:00
yesod-auth-oauth2.cabal Version bump 2014-09-17 22:19:56 -04:00

Yesod.Auth.OAuth2

OAuth2 AuthPlugins for Yesod.

Basic Usage

To use one of the supported providers:

import Yesod.Auth
import Yesod.Auth.OAuth2.Learn

instance YesodAuth App where
    -- ...

    -- https://learn.thoughtbot.com
    authPlugins _ = [oauth2Learn 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 :: AccessToken -> IO (Creds m)
makeCredentials token = do
    result <- authGetJSON 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