Coder Social home page Coder Social logo

yesod-auth-oauth2's Introduction

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

yesod-auth-oauth2's People

Contributors

abuibrahim avatar adarqui avatar bts avatar cpennington avatar danpalmer avatar drezil avatar duckofdoom avatar edwardbetts avatar freiric avatar gfontenot avatar gregwebs avatar jezen avatar jferris avatar jprider63 avatar jsteiner avatar k-bx avatar katyo avatar lukerandall avatar maxcan avatar paul-rouse avatar pbrisbin avatar saparvia avatar scan avatar silky avatar skade avatar snoyberg avatar ssaavedra avatar trofi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.