Code Monkey home page Code Monkey logo

omniauth-patreon's Introduction

omniauth-patreon

Gem Version Build Status

Patreon OAuth2 Strategy for OmniAuth 1.x and supports the OAuth 2.0 server-side flow.

You may view the Patreon API documentation here.

This project is a fork from omniauth/omniauth-uber, reconfigured for the Patreon API. A lot of the inner workings were inspired by Discourse's discourse-patreon code - thanks all! On the shoulders of giants, as it were ๐Ÿ™‚

Installation

Add to your Gemfile:

gem 'omniauth-patreon'

Then bundle install.

Usage

OmniAuth::Strategies::Patreon is simply Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.

Here's a quick example, adding the middleware to a Rails app in config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :patreon, ENV['PATREON_CLIENT_ID'], ENV['PATREON_CLIENT_SECRET']
end

Configuration

  • scope: A space separated list of permissions you want to request from the Patreon API (e.g: users my-campaign). View the Patreon API docs for Scope. Default: users pledges-to-me my-campaign
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :patreon, ENV['patreon_CLIENT_ID'], ENV['patreon_CLIENT_SECRET'], scope: 'campaigns pledges'
end

Auth Hash

Here's an example Auth Hash available in request.env['omniauth.auth']:

{
  "provider"=>"patreon",
  "uid"=>"12345678",
  "info"=>{
    "email"=>"[email protected]",
    "name"=>"Page",
    "access_token"=>"faketoken",
    "refresh_token"=>"faketoken"
  },
  "credentials"=>{
    "token"=>"faketoken",
    "refresh_token"=>"faketoken",
    "expires_at"=>1542163217,
    "expires"=>true
  },
  "extra"=>{
    # See expanded selection below
  }
}
Expanded OAuth response
{
  "provider"=>"patreon",
  "uid"=>"12345678",
  "info"=>{
    "email"=>"[email protected]",
    "name"=>"Page",
    "access_token"=>"faketoken",
    "refresh_token"=>"faketoken"
  },
  "credentials"=>{
    "token"=>"faketoken",
    "refresh_token"=>"faketoken",
    "expires_at"=>1542163217,
    "expires"=>true
  },
  "extra"=>{
    "raw_info"=>{
      "data"=>{
        "attributes"=>{
          "about"=>nil,
          "can_see_nsfw"=>true,
          "created"=>"2018-01-01T01:05:29+00:00",
          "default_country_code"=>nil,
          "discord_id"=>nil,
          "email"=>"[email protected]",
          "facebook"=>"https://www.facebook.com/pagename",
          "facebook_id"=>nil,
          "first_name"=>"First",
          "full_name"=>"First Last",
          "gender"=>0,
          "has_password"=>true,
          "image_url"=>"fakeurl",
          "is_deleted"=>false,
          "is_email_verified"=>true,
          "is_nuked"=>false,
          "is_suspended"=>false,
          "last_name"=>"Last",
          "social_connections"=>{
            "deviantart"=>nil,
            "discord"=>nil,
            "facebook"=>nil,
            "reddit"=>nil,
            "spotify"=>nil,
            "twitch"=>nil,
            "twitter"=>nil,
            "youtube"=>nil
          },
          "thumb_url"=>"fakeurl",
          "twitch"=>"https://www.twitch.tv/pagename",
          "twitter"=>"pagename",
          "url"=>"https://www.patreon.com/pagename",
          "vanity"=>"pagename",
          "youtube"=>"https://www.youtube.com/pagename"
        },
        "id"=>"12345678",
        "relationships"=>{
          "pledges"=>{
            "data"=>[]
          }
        },
        "type"=>"user"
      },
      "links"=>{
        "self"=>"https://www.patreon.com/api/user/12345678"
      }
    }
  }
}

Supported Ruby Versions

omniauth-patreon is tested under 2.2.6, 2.3.3, 2.4.1, and ruby-head.

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision. For example:

spec.add_dependency 'omniauth-patreon', '~> 1.0'

License

Copyright (c) 2018 by Kristian Freeman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

omniauth-patreon's People

Contributors

deanpcmad avatar kristianfreeman avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.