omniauth-patreon 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6204fc3fab14e14e5824fe56d0b0cfc72d4cf344
4
+ data.tar.gz: 5d5770b449297ce7709067f0f4d0ba90d23eb907
5
+ SHA512:
6
+ metadata.gz: 6e3526f837428919e1cea378c980df114160322646e9e05f69ca374582d5902db35607f21da23c18fc1fded7d8e31b147bc50ea18caaab026dd04739980157ac
7
+ data.tar.gz: 3466ccae50013ff4553c1f2d61b98a5bf5899b2e2524c7c5178596aaa182e4d0c366348abcb8319ee8ebb69dc63aa333249f82c92122641fbbbdf6283a960559
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .env
19
+ .rspec
@@ -0,0 +1,58 @@
1
+ # see https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+ # for default configuration
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.4
6
+ DisplayCopNames: true
7
+ Exclude:
8
+ - 'db/schema.rb'
9
+ - 'bin/*'
10
+ - 'vendor/**/*'
11
+
12
+ Rails:
13
+ Enabled: true
14
+
15
+ Documentation:
16
+ Enabled: false
17
+
18
+ Metrics/LineLength:
19
+ Max: 125
20
+ Exclude:
21
+ - 'db/migrate/*'
22
+ - 'config/initializers/devise.rb'
23
+
24
+ Metrics/MethodLength:
25
+ CountComments: false
26
+ Max: 10
27
+ Exclude:
28
+ - 'db/migrate/*'
29
+
30
+ Metrics/ModuleLength:
31
+ CountComments: false
32
+ Max: 100
33
+
34
+ Metrics/AbcSize:
35
+ # The ABC size is a calculated magnitude, so this number can be a Fixnum or a Float.
36
+ # http://c2.com/cgi/wiki?AbcMetric
37
+ Max: 15
38
+
39
+ Metrics/CyclomaticComplexity:
40
+ # http://www.rubydoc.info/github/bbatsov/rubocop/Rubocop/Cop/Style/CyclomaticComplexity
41
+ Max: 6
42
+
43
+ Metrics/PerceivedComplexity:
44
+ # http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/PerceivedComplexity
45
+ Max: 7
46
+
47
+ Metrics/ClassLength:
48
+ CountComments: false
49
+ Max: 100
50
+
51
+ Style/MultilineMethodCallIndentation:
52
+ EnforcedStyle: indented
53
+
54
+ Style/FrozenStringLiteralComment:
55
+ Enabled: false
56
+
57
+ Style/ClassAndModuleChildren:
58
+ Enabled: false
@@ -0,0 +1,9 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/tmilewski/rubocop-defaults/master/rubocop.yml
3
+
4
+ Style/FileName:
5
+ Enabled: false
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - 'tmp/**/*'
@@ -0,0 +1,17 @@
1
+ bundler_args: --without development
2
+ before_install: gem update bundler
3
+ cache: bundler
4
+ env:
5
+ global:
6
+ - JRUBY_OPTS="$JRUBY_OPTS --debug"
7
+ language: ruby
8
+ rvm:
9
+ - 2.2.6
10
+ - 2.3.3
11
+ - 2.4.1
12
+ - ruby-head
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ fast_finish: true
17
+ sudo: false
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :development do
6
+ gem 'rubocop', '>= 0.48.1'
7
+ end
8
+
9
+ group :test do
10
+ gem 'coveralls', require: false
11
+ gem 'rack-test'
12
+ gem 'rspec', '~> 3.6.0'
13
+ gem 'simplecov', require: false
14
+ end
15
+
16
+ gemspec
@@ -0,0 +1,175 @@
1
+ # omniauth-patreon
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/omniauth-patreon.svg)](http://badge.fury.io/rb/omniauth-patreon)
4
+ [![Build Status](https://travis-ci.org/signalnerve/omniauth-patreon.svg?branch=master)](https://travis-ci.org/signalnerve/omniauth-patreon)
5
+
6
+ Patreon OAuth2 Strategy for OmniAuth 1.x and supports the OAuth 2.0 server-side flow.
7
+
8
+ You may view the Patreon API documentation [here](https://www.patreon.com/portal/).
9
+
10
+ This project is a fork from [omniauth/omniauth-uber](https://github.com/omniauth/omniauth-uber), reconfigured for the Patreon API 🙂
11
+
12
+ ## Installation
13
+
14
+ Add to your `Gemfile`:
15
+
16
+ ```ruby
17
+ gem 'omniauth-patreon'
18
+ ```
19
+
20
+ Then `bundle install`.
21
+
22
+ ## Usage
23
+
24
+ `OmniAuth::Strategies::Patreon` is simply Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
25
+
26
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
27
+
28
+ ```ruby
29
+ Rails.application.config.middleware.use OmniAuth::Builder do
30
+ provider :patreon, ENV['PATREON_CLIENT_ID'], ENV['PATREON_CLIENT_SECRET']
31
+ end
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ - `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](https://docs.patreon.com/#scopes). Default: `users pledges-to-me my-campaign`
37
+
38
+ ```ruby
39
+ Rails.application.config.middleware.use OmniAuth::Builder do
40
+ provider :patreon, ENV['patreon_CLIENT_ID'], ENV['patreon_CLIENT_SECRET'], scope: 'campaigns pledges'
41
+ end
42
+ ```
43
+
44
+ ## Auth Hash
45
+
46
+ Here's an example _Auth Hash_ available in `request.env['omniauth.auth']`:
47
+
48
+ ```ruby
49
+ {
50
+ "provider"=>"patreon",
51
+ "uid"=>"12345678",
52
+ "info"=>{
53
+ "email"=>"my@email.com",
54
+ "name"=>"Page",
55
+ "access_token"=>"faketoken",
56
+ "refresh_token"=>"faketoken"
57
+ },
58
+ "credentials"=>{
59
+ "token"=>"faketoken",
60
+ "refresh_token"=>"faketoken",
61
+ "expires_at"=>1542163217,
62
+ "expires"=>true
63
+ },
64
+ "extra"=>{
65
+ # See expanded selection below
66
+ }
67
+ }
68
+ ```
69
+
70
+ <details>
71
+
72
+ <summary>Expanded OAuth response</summary>
73
+
74
+ ```ruby
75
+ {
76
+ "provider"=>"patreon",
77
+ "uid"=>"12345678",
78
+ "info"=>{
79
+ "email"=>"my@email.com",
80
+ "name"=>"Page",
81
+ "access_token"=>"faketoken",
82
+ "refresh_token"=>"faketoken"
83
+ },
84
+ "credentials"=>{
85
+ "token"=>"faketoken",
86
+ "refresh_token"=>"faketoken",
87
+ "expires_at"=>1542163217,
88
+ "expires"=>true
89
+ },
90
+ "extra"=>{
91
+ "raw_info"=>{
92
+ "data"=>{
93
+ "attributes"=>{
94
+ "about"=>nil,
95
+ "can_see_nsfw"=>true,
96
+ "created"=>"2018-01-01T01:05:29+00:00",
97
+ "default_country_code"=>nil,
98
+ "discord_id"=>nil,
99
+ "email"=>"my@email.com",
100
+ "facebook"=>"https://www.facebook.com/pagename",
101
+ "facebook_id"=>nil,
102
+ "first_name"=>"First",
103
+ "full_name"=>"First Last",
104
+ "gender"=>0,
105
+ "has_password"=>true,
106
+ "image_url"=>"fakeurl",
107
+ "is_deleted"=>false,
108
+ "is_email_verified"=>true,
109
+ "is_nuked"=>false,
110
+ "is_suspended"=>false,
111
+ "last_name"=>"Last",
112
+ "social_connections"=>{
113
+ "deviantart"=>nil,
114
+ "discord"=>nil,
115
+ "facebook"=>nil,
116
+ "reddit"=>nil,
117
+ "spotify"=>nil,
118
+ "twitch"=>nil,
119
+ "twitter"=>nil,
120
+ "youtube"=>nil
121
+ },
122
+ "thumb_url"=>"fakeurl",
123
+ "twitch"=>"https://www.twitch.tv/pagename",
124
+ "twitter"=>"pagename",
125
+ "url"=>"https://www.patreon.com/pagename",
126
+ "vanity"=>"pagename",
127
+ "youtube"=>"https://www.youtube.com/pagename"
128
+ },
129
+ "id"=>"12345678",
130
+ "relationships"=>{
131
+ "pledges"=>{
132
+ "data"=>[]
133
+ }
134
+ },
135
+ "type"=>"user"
136
+ },
137
+ "links"=>{
138
+ "self"=>"https://www.patreon.com/api/user/12345678"
139
+ }
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ </details>
146
+
147
+ ## Supported Ruby Versions
148
+
149
+ `omniauth-patreon` is tested under 2.2.6, 2.3.3, 2.4.1, and ruby-head.
150
+
151
+ ## Versioning
152
+
153
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
154
+ of this scheme should be reported as bugs. Specifically, if a minor or patch
155
+ version is released that breaks backward compatibility, that version should be
156
+ immediately yanked and/or a new version should be immediately released that
157
+ restores compatibility. Breaking changes to the public API will only be
158
+ introduced with new major versions. As a result of this policy, you can (and
159
+ should) specify a dependency on this gem using the [Pessimistic Version
160
+ Constraint][pvc] with two digits of precision. For example:
161
+
162
+ spec.add_dependency 'omniauth-patreon', '~> 1.0'
163
+
164
+ [semver]: http://semver.org/
165
+ [pvc]: http://docs.rubygems.org/read/chapter/16#page74
166
+
167
+ ## License
168
+
169
+ Copyright (c) 2018 by Kristian Freeman
170
+
171
+ 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:
172
+
173
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
174
+
175
+ 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.
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task test: :spec
7
+
8
+ begin
9
+ require 'rubocop/rake_task'
10
+ RuboCop::RakeTask.new
11
+ rescue LoadError
12
+ task :rubocop do
13
+ $stderr.puts 'Rubocop is disabled'
14
+ end
15
+ end
16
+
17
+ task default: %i[spec rubocop]
@@ -0,0 +1,2 @@
1
+ require 'omniauth/patreon/version'
2
+ require 'omniauth/strategies/patreon'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Patreon
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Patreon < OmniAuth::Strategies::OAuth2
6
+ option :name, 'patreon'
7
+
8
+ option :client_options,
9
+ site: 'https://www.patreon.com',
10
+ authorize_url: 'https://www.patreon.com/oauth2/authorize',
11
+ token_url: 'https://api.patreon.com/oauth2/token'
12
+
13
+ uid { raw_info['data']['id'].to_s }
14
+
15
+ info do
16
+ {
17
+ email: raw_info['data']['attributes']['email'],
18
+ name: raw_info['data']['attributes']['full_name'],
19
+ access_token: access_token.token,
20
+ refresh_token: access_token.refresh_token
21
+ }
22
+ end
23
+
24
+ extra do
25
+ { raw_info: raw_info }
26
+ end
27
+
28
+ def raw_info
29
+ @raw_info ||= begin
30
+ response = client.request(:get, "https://api.patreon.com/oauth2/api/current_user", headers: {
31
+ 'Authorization' => "Bearer #{access_token.token}"
32
+ }, parse: :json)
33
+ response.parsed
34
+ end
35
+ end
36
+
37
+ def callback_url
38
+ full_host + script_name + callback_path
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+ require 'omniauth/patreon/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'omniauth-patreon'
8
+ s.version = OmniAuth::Patreon::VERSION
9
+ s.authors = ['Kristian Freeman']
10
+ s.email = ['kristian@bytesized.xyz']
11
+ s.summary = 'Patreon strategy for OmniAuth'
12
+ s.description = 'Patreon strategy for OmniAuth v1.2'
13
+ s.homepage = 'https://github.com/tmilewski/omniauth-patreon'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_runtime_dependency 'omniauth', '~> 1.2'
22
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
23
+
24
+ s.add_development_dependency 'dotenv', '>= 2.0'
25
+ s.add_development_dependency 'sinatra', '>= 2.0'
26
+ end
@@ -0,0 +1,45 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'dotenv'
5
+ require 'sinatra'
6
+ require 'omniauth'
7
+ require 'omniauth-patreon'
8
+
9
+ Dotenv.load
10
+
11
+ enable :sessions
12
+
13
+ use OmniAuth::Builder do
14
+ provider :patreon, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'] # , :scope => 'profile'
15
+ end
16
+
17
+ get '/' do
18
+ <<-HTML
19
+ <a href='/auth/patreon'>Sign in with patreon</a>
20
+ HTML
21
+ end
22
+
23
+ get '/auth/failure' do
24
+ env['omniauth.error'].to_s
25
+ end
26
+
27
+ get '/auth/:name/callback' do
28
+ auth = request.env['omniauth.auth']
29
+
30
+ puts %(
31
+ >> UID
32
+ #{auth.uid.inspect}
33
+
34
+ >> CREDENTIALS
35
+ #{auth.credentials.inspect}
36
+
37
+ >> INFO
38
+ #{auth.info.inspect}
39
+ #
40
+ >> EXTRA
41
+ #{auth.extra.inspect}
42
+ )
43
+
44
+ 'Check logs for user information.'
45
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Patreon do
4
+ subject do
5
+ @subject ||= begin
6
+ @options ||= {}
7
+ args = ['client_id', 'client_secret', @options].compact
8
+ OmniAuth::Strategies::Patreon.new(*args)
9
+ end
10
+ end
11
+
12
+ context 'client options' do
13
+ it 'should have correct name' do
14
+ expect(subject.options.name).to eq('patreon')
15
+ end
16
+
17
+ it 'should have correct site' do
18
+ expect(subject.options.client_options.site).to eq('https://www.patreon.com/api/oauth2/api')
19
+ end
20
+
21
+ it 'should have correct authorize url' do
22
+ expect(subject.options.client_options.authorize_url).to eq('https://patreon.com/oauth2/authorize')
23
+ end
24
+
25
+ it 'should have correct access token url' do
26
+ expect(subject.options.client_options.token_url).to eq('https://patreon.com/api/oauth2/token')
27
+ end
28
+
29
+ it 'should indicate that the provider ignores the state parameted' do
30
+ expect(subject.options.provider_ignores_state).to eq false
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+
8
+ require 'omniauth'
9
+ require 'omniauth-patreon'
10
+
11
+ RSpec.configure do |config|
12
+ config.extend OmniAuth::Test::StrategyMacros, type: :strategy
13
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-patreon
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kristian Freeman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: Patreon strategy for OmniAuth v1.2
70
+ email:
71
+ - kristian@bytesized.xyz
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rubocop-https---raw-githubusercontent-com-tmilewski-rubocop-defaults-master-rubocop-yml"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - lib/omniauth-patreon.rb
84
+ - lib/omniauth/patreon/version.rb
85
+ - lib/omniauth/strategies/patreon.rb
86
+ - omniauth-patreon.gemspec
87
+ - spec/app.rb
88
+ - spec/omniauth/strategies/uber_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/tmilewski/omniauth-patreon
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.11
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Patreon strategy for OmniAuth
114
+ test_files:
115
+ - spec/app.rb
116
+ - spec/omniauth/strategies/uber_spec.rb
117
+ - spec/spec_helper.rb