OAuth2 authentication for yesod
Go to file
patrick brisbin 9b028535bd
Add potential, currently non-functioning tests
Approach so far:

The SpecHelper sets up an example App type which should (theoretically)
be enough to get some fake requests and responses going, as in any
yesod-test-based suite.

The spec then tries to build an example plugin and make assertions on
how it dispatches. This is currently falling down on subsite-related
type errors (see commented attempts).

Another potential direction is to define the YesodAuth instance for App
to specify authPlugins built using the library. With that, we might be
able to create specs using yesod-test that exercise aspects of the
plugins in an indirect way, but enough to make useful assertions.
2016-01-04 13:02:09 -05:00
test Add potential, currently non-functioning tests 2016-01-04 13:02:09 -05:00
Yesod/Auth Add user location 2016-01-04 12:34:35 -05:00
.gitignore Add stack support 2016-01-03 10:37:52 -05:00
circle.yml Replace Travis with Circle 2016-01-03 10:39:26 -05: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
stack.yaml Add stack support 2016-01-03 10:37:52 -05:00
yesod-auth-oauth2.cabal Add potential, currently non-functioning tests 2016-01-04 13:02:09 -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 = "..."

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