OAuth2 authentication for yesod
Go to file
Freiric Barral ec80c8f75e fix cabal file: take into account the split of network from version 2.6,
and avoid authenticate 1.3.2.6 which gave the following strange error:
...
Building authenticate-1.3.2.6...
Preprocessing library authenticate-1.3.2.6...
[1 of 9] Compiling OpenId2.XRDS     ( OpenId2/XRDS.hs, dist/dist-sandbox-a1429708/build/OpenId2/XRDS.o )
[2 of 9] Compiling Web.Authenticate.OpenId.Providers ( Web/Authenticate/OpenId/Providers.hs, dist/dist-sandbox-a1429708/build/Web/Authenticate/OpenId/Providers.o )
[3 of 9] Compiling Web.Authenticate.BrowserId ( Web/Authenticate/BrowserId.hs, dist/dist-sandbox-a1429708/build/Web/Authenticate/BrowserId.o )

Web/Authenticate/BrowserId.hs:15:22:
    Module ‘Data.Conduit’ does not export ‘MonadBaseControl’

Web/Authenticate/BrowserId.hs:15:40:
    Module ‘Data.Conduit’ does not export ‘MonadResource’
Failed to install authenticate-1.3.2.6
2014-08-29 20:57:39 +02:00
Yesod/Auth Add a github OAuth2 provider 2014-08-29 20:57:39 +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 fix cabal file: take into account the split of network from version 2.6, 2014-08-29 20:57:39 +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.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