From 3c3c8f019d27ca32b3562af2d5cfc462cd829c0e Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 20 Feb 2014 15:47:05 -0500 Subject: [PATCH] Add content to README --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index e69de29..522cf27 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,56 @@ +# Yesod.Auth.OAuth2 + +OAuth2 `AuthPlugin`s for Yesod. + +## Basic Usage + +To use one of the supported providers: + +```haskell +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: + +```haskell +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*