omniauth-stripe-connect-v2 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3736e47722dbe9012273102dc574a3d5a634785bb317abdb2b18578ecbf21c9c
4
+ data.tar.gz: a58dadf99dca266d614eb9b883bc58ca092a66c2a98394adcf1ae9d5c9a94763
5
+ SHA512:
6
+ metadata.gz: 625fe727bc4b5721c1ffb00ce5dba31580d903c26dee16b6024c17aa3e38862f66df901d43c98e7232eb045a09739a62769dab117b54a3d7ca5d9fbed09e4880
7
+ data.tar.gz: bbbf96304cf1d86538103cd516fd09441c54030c90d76bcf67af3181ffaa199903f267addcb6aabe0a22415a31d9bc86048336fb48a89b0399f44c9a7e362c8f
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ *.rvmrc
4
+ .ruby-version
5
+ .ruby-gemset
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec_v2/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ example
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rake'
3
+
4
+ # Specify your gem's dependencies in omniauth-stripe-connect.gemspec
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'rspec', '>= 2.14'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2023 Gumroad
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # OmniAuth::StripeConnectV2
2
+
3
+ Stripe Connect OAuth2 Strategy for OmniAuth 1.0.
4
+
5
+ Supports the OAuth 2.0 server-side and client-side flows.
6
+ Read the Stripe Connect docs for more details: https://stripe.com/connect
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'omniauth-stripe-connect-v2'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install omniauth-stripe-connect-v2
21
+
22
+ ## Usage
23
+
24
+ OmniAuth::Strategies::StripeConnectV2 is simply a Rack middleware. Read the OmniAuth
25
+ 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
26
+
27
+ ### Non-Devise
28
+ Here's a quick example, adding the middleware to a Rails app in
29
+ `config/initializers/omniauth.rb`:
30
+
31
+ ```ruby
32
+ Rails.application.config.middleware.use OmniAuth::Builder do
33
+ provider :stripe_connect, ENV['STRIPE_CONNECT_CLIENT_ID'], ENV['STRIPE_SECRET']
34
+ end
35
+ ```
36
+
37
+ ### Devise
38
+
39
+ You need to declare the provider in your `config/initializers/devise.rb`:
40
+
41
+ ```ruby
42
+ config.omniauth :stripe_connect, "STRIPE_CONNECT_CLIENT_ID", "STRIPE_SECRET"
43
+ ```
44
+
45
+ You'll also need to add some configuration to your devise model (e.g. User in `app/models/user.rb`) along with any other OmniAuth providers you might have:
46
+ ```ruby
47
+ :omniauthable, :omniauth_providers => [:stripe_connect]
48
+ ```
49
+
50
+ ### General Usage
51
+
52
+ Your `STRIPE_CONNECT_CLIENT_ID` is application-specific and your `STRIPE_SECRET` is account-specific and may also be known as your Stripe API key or Stripe Private key.
53
+
54
+ Edit your `routes.rb` file to have:
55
+ `devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }`
56
+
57
+ And create a file called `omniauth_callbacks_controller.rb` which should have this inside:
58
+ ```ruby
59
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
60
+
61
+ def stripe_connect
62
+ # Delete the code inside of this method and write your own.
63
+ # The code below is to show you where to access the data.
64
+ raise request.env["omniauth.auth"].to_yaml
65
+ end
66
+ end
67
+ ```
68
+
69
+ Make sure to go to Stripe's Account Settings > Applications and set your Redirect URL to:
70
+ `http://localhost:3003/users/auth/stripe_connect/callback`
71
+
72
+ The Webhook URL will be something similar:
73
+ `http://www.yourdomain.com/users/auth/stripe_connect/callback`
74
+
75
+ Then you can hit `/auth/stripe_connect`
76
+
77
+ If you hit `/auth/stripe_connect` with any query params, they will be passed along to Stripe. You can access these params from `request.env['omniauth.params']`. Read [Stripe's OAuth Reference](https://stripe.com/docs/connect/reference) for more information.
78
+
79
+ ## Auth Hash
80
+
81
+ Here is an example of the Auth Hash you get back from calling `request.env['omniauth.auth']`:
82
+
83
+ ```ruby
84
+ {
85
+ "provider"=>"stripe_connect",
86
+ "uid"=>"<STRIPE_USER_ID>",
87
+ "info"=> {
88
+ "email"=>"email@example.com",
89
+ "name"=>"Name",
90
+ "nickname"=>"Nickname",
91
+ "scope"=>"read_write", # or "read_only"
92
+ "livemode"=>false,
93
+ "stripe_publishable_key"=>"<STRIPE_PUBLISHABLE_KEY>",
94
+ },
95
+ "credentials"=> {
96
+ "token"=>"<STRIPE_ACCESS_TOKEN>",
97
+ "refresh_token"=>"<STRIPE_REFRESH_TOKEN>",
98
+ "expires"=>false
99
+ },
100
+ "extra"=> {
101
+ "raw_info"=> {
102
+ "token_type"=>"bearer",
103
+ "stripe_user_id"=>"<STRIPE_USER_ID>",
104
+ "scope"=>"read_only",
105
+ "stripe_publishable_key"=>"<STRIPE_PUBLISHABLE_KEY>",
106
+ "livemode"=>false
107
+ },
108
+ "extra_info"=> {
109
+ "business_logo"=>"https://stripe.com/business_logo.png",
110
+ "business_name"=>"Business Name",
111
+ "business_url"=>"example.com",
112
+ "charges_enabled"=>true,
113
+ "country"=>"US",
114
+ "default_currency"=>"eur",
115
+ "details_submitted"=>true,
116
+ "display_name"=>"Business Name",
117
+ "email"=>"email@example.com",
118
+ "id"=>"<STRIPE_USER_ID>",
119
+ "managed"=>false,
120
+ "object"=>"account",
121
+ "statement_descriptor"=>"EXAMPLE.COM",
122
+ "support_email"=>"support@example.com",
123
+ "support_phone"=>"123456789",
124
+ "timezone"=>"Europe/Berlin",
125
+ "transfers_enabled"=>true
126
+ }
127
+ }
128
+ }
129
+ ```
130
+
131
+ ## Additional Tutorials
132
+ [Stripe Connect in Rails Tutorial](https://web.archive.org/web/20160313043319/http://www.munocreative.com/nerd-notes/winvoice)
133
+
134
+ ## Contributing
135
+
136
+ 1. Fork it
137
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
138
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
139
+ 4. Push to the branch (`git push origin my-new-feature`)
140
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,100 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class StripeConnectV2 < OmniAuth::Strategies::OAuth2
6
+ option :name, :stripe_connect_v2
7
+
8
+ option :client_options, {
9
+ :site => 'https://connect.stripe.com'
10
+ }
11
+
12
+ option :authorize_options, [:scope, :stripe_landing, :always_prompt]
13
+ option :provider_ignores_state, true
14
+
15
+ uid { raw_info[:stripe_user_id] }
16
+
17
+ info do
18
+ {
19
+ :name => extra_info[:display_name] || extra_info[:business_name] || extra_info[:email],
20
+ :email => extra_info[:email],
21
+ :nickname => extra_info[:display_name],
22
+ :scope => raw_info[:scope],
23
+ :livemode => raw_info[:livemode],
24
+ :stripe_publishable_key => raw_info[:stripe_publishable_key]
25
+ }
26
+ end
27
+
28
+ extra do
29
+ e = {
30
+ :raw_info => raw_info
31
+ }
32
+ e[:extra_info] = extra_info unless skip_info?
33
+
34
+ e
35
+ end
36
+
37
+ credentials do
38
+ hash = {'token' => access_token.token}
39
+ hash.merge!('refresh_token' => access_token.refresh_token) if access_token.refresh_token
40
+ hash.merge!('expires_at' => access_token.expires_at) if access_token.expires?
41
+ hash.merge!('expires' => access_token.expires?)
42
+ hash
43
+ end
44
+
45
+ def raw_info
46
+ @raw_info ||= deep_symbolize(access_token.params)
47
+ end
48
+
49
+ def extra_info
50
+ @extra_info ||= deep_symbolize(access_token.get("https://api.stripe.com/v1/account").parsed)
51
+ end
52
+
53
+ def redirect_params
54
+ if options.key?(:callback_path) || OmniAuth.config.full_host
55
+ {:redirect_uri => callback_url}
56
+ else
57
+ {}
58
+ end
59
+ end
60
+
61
+ # NOTE: We call redirect_params AFTER super in these methods intentionally
62
+ # the OAuth2 strategy uses the authorize_params and token_params methods
63
+ # to set up some state for testing that we need in redirect_params
64
+
65
+ def authorize_params
66
+ params = super
67
+ params = params.merge(request_params) unless OmniAuth.config.test_mode
68
+ redirect_params.merge(params)
69
+ end
70
+
71
+ def token_params
72
+ params = super.to_hash(:symbolize_keys => true) \
73
+ .merge(:headers => { 'Authorization' => "Bearer #{client.secret}" })
74
+
75
+ redirect_params.merge(params)
76
+ end
77
+
78
+ def callback_url
79
+ full_host + script_name + callback_path
80
+ end
81
+
82
+ def request_phase
83
+ redirect client.auth_code.authorize_url(authorize_params)
84
+ end
85
+
86
+ def build_access_token
87
+ verifier = request.params['code']
88
+ client.auth_code.get_token(verifier, token_params)
89
+ end
90
+
91
+ def request_params
92
+ request.params.except(*request_blacklisted_params)
93
+ end
94
+
95
+ def request_blacklisted_params
96
+ %w(_method)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/stripe_connect_v2'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module StripeConnectV2
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-stripe-connect/version"
2
+ require 'omniauth/stripe_connect'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-stripe-connect-v2/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Hide Shidara"]
6
+ gem.email = ["hshidaragumroad@gmail.com"]
7
+ gem.description = %q{Stripe Connect OAuth2 Strategy for OmniAuth 2.0.}
8
+ gem.summary = %q{
9
+ Supports the OAuth 2.0 server-side and client-side flows.
10
+ Read the Stripe Connect docs for more details: https://stripe.com/docs/connect
11
+ }
12
+ gem.homepage = "https://stripe.com/docs/connect"
13
+
14
+ gem.files = `git ls-files | grep -v example`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.name = "omniauth-stripe-connect-v2"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = OmniAuth::StripeConnectV2::VERSION
20
+ gem.license = "MIT"
21
+
22
+ gem.add_dependency 'omniauth', '~> 2.0'
23
+ gem.add_dependency 'omniauth-oauth2', '~> 1.4'
24
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::StripeConnectV2 do
4
+ let(:fresh_strategy) { Class.new(OmniAuth::Strategies::StripeConnectV2) }
5
+
6
+
7
+ before(:each) do
8
+ OmniAuth.config.test_mode = true
9
+ @old_host = OmniAuth.config.full_host
10
+ end
11
+
12
+ after(:each) do
13
+ OmniAuth.config.full_host = @old_host
14
+ OmniAuth.config.test_mode = false
15
+ end
16
+
17
+ describe '#authorize_params' do
18
+ subject { fresh_strategy }
19
+
20
+ it 'should include redirect_uri if full_host is set' do
21
+ OmniAuth.config.full_host = 'https://foo.com/'
22
+ instance = subject.new('abc', 'def')
23
+
24
+ instance.authorize_params[:redirect_uri].should =~ /\Ahttps:\/\/foo\.com/
25
+ end
26
+
27
+ it 'should include redirect_uri if callback_path is set' do
28
+ # TODO: It would be nice to grab this from the request URL
29
+ # instead of setting it on the config
30
+ OmniAuth.config.full_host = 'https://foo.com/'
31
+ instance = subject.new('abc', 'def', :callback_path => 'bar/baz')
32
+
33
+ instance.authorize_params[:redirect_uri].should == 'https://foo.com/bar/baz'
34
+ end
35
+
36
+ it 'should not include redirect_uri by default' do
37
+ instance = subject.new('abc', 'def')
38
+
39
+ expect(instance.authorize_params[:redirect_uri]).to be_nil
40
+ end
41
+ end
42
+
43
+ describe '#token_params' do
44
+ subject { fresh_strategy }
45
+
46
+ # NOTE: We call authorize_params first in each of these methods
47
+ # since the OAuth2 gem uses it to setup some state for testing
48
+
49
+ it 'should include redirect_uri if full_host is set' do
50
+ OmniAuth.config.full_host = 'https://foo.com/'
51
+ instance = subject.new('abc', 'def')
52
+
53
+ instance.authorize_params
54
+ instance.token_params[:redirect_uri].should =~ /\Ahttps:\/\/foo\.com/
55
+ end
56
+
57
+ it 'should include redirect_uri if callback_path is set' do
58
+ # TODO: It would be nice to grab this from the request URL
59
+ # instead of setting it on the config
60
+ OmniAuth.config.full_host = 'https://foo.com/'
61
+ instance = subject.new('abc', 'def', :callback_path => 'bar/baz')
62
+
63
+ instance.authorize_params
64
+ instance.token_params[:redirect_uri].should == 'https://foo.com/bar/baz'
65
+ end
66
+
67
+ it 'should not include redirect_uri by default' do
68
+ instance = subject.new('abc', 'def')
69
+
70
+ instance.authorize_params
71
+ expect(instance.token_params[:redirect_uri]).to be_nil
72
+ end
73
+ end
74
+
75
+ describe '#callback_url' do
76
+ subject { fresh_strategy }
77
+ OmniAuth.config.full_host = 'https://foo.com/'
78
+
79
+ it 'returns a url with the host and path' do
80
+ instance = subject.new('abc', 'def', :callback_path => 'bar/baz')
81
+ instance.authorize_params
82
+ expect(instance.callback_url).to eq 'https://foo.com/bar/baz'
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'omniauth-stripe-connect-v2'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-stripe-connect-v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hide Shidara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-07-04 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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ description: Stripe Connect OAuth2 Strategy for OmniAuth 2.0.
42
+ email:
43
+ - hshidaragumroad@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/omniauth-stripe-connect-v2.rb
54
+ - lib/omniauth-stripe-connect-v2/version.rb
55
+ - lib/omniauth/strategies/stripe_connect_v2.rb
56
+ - lib/omniauth/stripe_connect_v2.rb
57
+ - omniauth-stripe-connect-v2.gemspec
58
+ - spec_v2/omniauth/strategies/stripe_connect_v2_spec.rb
59
+ - spec_v2/spec_helper.rb
60
+ homepage: https://stripe.com/docs/connect
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.4.10
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: 'Supports the OAuth 2.0 server-side and client-side flows. Read the Stripe
83
+ Connect docs for more details: https://stripe.com/docs/connect'
84
+ test_files: []