OAuth2 authentication for yesod
Go to file
2018-02-12 09:10:34 -08:00
.circleci Skip linting step on 8.0 2018-01-26 12:18:46 -05:00
example Add example application 2016-02-10 09:50:51 -05:00
src Remove extra fields from Nylas provider 2018-02-12 09:10:34 -08:00
test Project setup files 2018-01-23 10:16:22 -05:00
.gitignore Ignore TESTREPORT, used in --rerun testing 2018-01-27 08:10:55 -05:00
.hlint.yaml Address HLint issues 2018-01-23 10:16:22 -05:00
.stylish-haskell.yaml Project setup files 2018-01-23 10:16:22 -05:00
CHANGELOG.md Back-fill a CHANGELOG 2018-01-25 17:20:33 -05:00
LICENSE Correct license information 2018-01-26 13:58:16 -05:00
Makefile Test all supported GHCs & nightly 2018-01-26 12:18:46 -05:00
package.yaml Re-structure modules 2018-01-27 08:10:55 -05:00
README.md Back-fill a CHANGELOG 2018-01-25 17:20:33 -05:00
Setup.lhs Initial import 2013-07-14 11:11:44 +02:00
stack.yaml Drop support for GHC < 7.10 2018-01-24 08:04:58 -05: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 = "..."

Some plugins, such as GitHub and Slack, have scoped functions for requesting additional information:

import Yesod.Auth
import Yesod.Auth.OAuth2.Slack

instance YesodAuth App where
    -- ...

    authPlugins _ =
        [oauth2SlackScoped clientId clientSecret slackScopes]
      where
        slackScopes = [SlackEmailScope, SlackAvatarScope, SlackTeamScope]

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

Development & Tests

stack setup
stack build --dependencies-only
stack build --pedantic --test

CHANGELOG | LICENSE