mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-01-12 04:08:30 +01:00
OAuth2 authentication for yesod
Marks "location" as Maybe in GitHub responses. Without this, users could experience an InvalidProfileResponse error when missing. Also fixes cases where fields were Maybe, but the (.:?) combinator was not being used in the parser. |
||
|---|---|---|
| example | ||
| test | ||
| Yesod/Auth | ||
| .gitignore | ||
| circle.yml | ||
| LICENSE | ||
| README.md | ||
| Setup.lhs | ||
| stack.yaml | ||
| yesod-auth-oauth2.cabal | ||
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