omniauth-mercadopago 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6de80d99ce1598a7b3f66099ee780bbbb1aab8a
4
+ data.tar.gz: 5eaa299406d866e4b1661b0f207e532552ce34f3
5
+ SHA512:
6
+ metadata.gz: 84cf211d984acadbfb01ea9ddc467ef07b523ae21f2746872e7b1800152cb11cea8aa3946b6d2fc82d50205a15b986cced97f8c00fce74e6e7786cac6e71da1b
7
+ data.tar.gz: edb8c905a3ad284a7ac5f50836c2a0750b2b0680fff08bf15065c791f1eb477f61ecf0f9e6e875451d0197576dcbee8ad62cbf7b3d6458ff4d0b863d6264263f
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .DS_Store
12
+ .gs
13
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format=progress
data/.rubocop.yml ADDED
@@ -0,0 +1,42 @@
1
+ Metrics/BlockNesting:
2
+ Max: 2
3
+
4
+ Metrics/LineLength:
5
+ AllowURI: true
6
+ Enabled: false
7
+
8
+ Metrics/MethodLength:
9
+ CountComments: false
10
+ Max: 10
11
+
12
+ Metrics/ParameterLists:
13
+ Max: 4
14
+ CountKeywordArgs: true
15
+
16
+ Style/AccessModifierIndentation:
17
+ EnforcedStyle: outdent
18
+
19
+ Style/CollectionMethods:
20
+ PreferredMethods:
21
+ map: 'collect'
22
+ reduce: 'inject'
23
+ find: 'detect'
24
+ find_all: 'select'
25
+
26
+ Style/Documentation:
27
+ Enabled: false
28
+
29
+ Style/DoubleNegation:
30
+ Enabled: false
31
+
32
+ Style/HashSyntax:
33
+ EnforcedStyle: hash_rockets
34
+
35
+ Style/SpaceInsideHashLiteralBraces:
36
+ EnforcedStyle: no_space
37
+
38
+ Style/StringLiterals:
39
+ EnforcedStyle: double_quotes
40
+
41
+ Style/TrailingComma:
42
+ EnforcedStyleForMultiline: 'comma'
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.5
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "coveralls"
5
+ gem "json", :platforms => [:jruby, :ruby_18, :ruby_19]
6
+ gem "mime-types", "~> 1.25", :platforms => [:jruby, :ruby_18]
7
+ gem "rack-test"
8
+ gem "rest-client", "~> 1.7.3", :platforms => [:jruby, :ruby_18]
9
+ gem "rspec", "~> 3.2"
10
+ gem "rubocop", ">= 0.30", :platforms => [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
11
+ gem "simplecov", ">= 0.9"
12
+ gem "webmock"
13
+ end
14
+
15
+ # Specify your gem's dependencies in omniauth-mercadopago.gemspec
16
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Agustin Cavilliotti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ ```ruby
6
+ gem 'omniauth-mercadopago'
7
+ ```
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install omniauth-mercadopago
16
+
17
+ ## Usage
18
+
19
+ TODO:
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omniauth-mercadopago. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
30
+
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
35
+
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ require File.expand_path("../lib/omniauth-mercadopago/version", __FILE__)
5
+
6
+ RSpec::Core::RakeTask.new
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 test: :spec
18
+
19
+ task :build do
20
+ sh "gem build omniauth-mercadopago.gemspec"
21
+ end
22
+
23
+ task release: :build do
24
+ sh "git push origin master"
25
+ sh "gem push omniauth-mercadopago-#{OmniAuth::Mercadopago::VERSION}.gem"
26
+ end
27
+
28
+ task :console do
29
+ sh "irb -rubygems -I lib/omniauth -r mercadopago.rb"
30
+ end
31
+
32
+ task default: [:spec, :rubocop]
@@ -0,0 +1,103 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Mercadopago < OmniAuth::Strategies::OAuth2
6
+ API_ROOT_URL = "https://api.mercadopago.com"
7
+ AUTH_URL = "https://auth.mercadopago.com/authorization"
8
+ OAUTH_URL = "/oauth/token"
9
+
10
+ option :name, "mercadopago"
11
+
12
+ # This is where you pass the options you would pass when
13
+ # initializing your consumer from the OAuth gem.
14
+ option :client_options, {
15
+ site: API_ROOT_URL,
16
+ authorize_url: AUTH_URL,
17
+ token_url: OAUTH_URL
18
+ }
19
+
20
+ def request_phase
21
+ super
22
+ end
23
+
24
+ def callback_url
25
+ # As ariginally was in the omniauth-oauth2 gem
26
+ # https://github.com/intridea/omniauth-oauth2/pull/70/files
27
+ full_host + script_name + callback_path
28
+ end
29
+
30
+ def authorize_params
31
+ logger.info " === callback_url: #{callback_url} === "
32
+ super.tap do |params|
33
+ params[:response_type ] = "code"
34
+ params[:client_id] = client.id
35
+ params[:redirect_uri] = callback_url.to_s.downcase
36
+ end
37
+ end
38
+
39
+ def build_access_token
40
+ logger.info " === build_access_token callback_url= #{callback_url} === "
41
+ logger.info " === build_access_token options= #{options} === "
42
+ token_params = {
43
+ code: request.params['code'],
44
+ redirect_uri: callback_url.to_s.downcase,
45
+ client_id: client.id,
46
+ client_secret: client.secret,
47
+ grant_type: 'authorization_code'
48
+ }
49
+ client.get_token(token_params)
50
+ end
51
+
52
+ # data response of api
53
+ uid { raw_info['id'].to_s }
54
+
55
+ info do
56
+ prune!({
57
+ username: raw_info['nickname'],
58
+ email: raw_info['email'],
59
+ first_name: raw_info['first_name'],
60
+ last_name: raw_info['last_name'],
61
+ image: raw_info['logo'],
62
+ url: raw_info['permalink']
63
+ })
64
+ end
65
+
66
+ extra do
67
+ hash = {}
68
+ hash[:access_token] = access_token.to_hash
69
+ hash[:raw_info] = raw_info unless skip_info?
70
+ prune! hash
71
+ end
72
+
73
+ def raw_info
74
+ @raw_info ||= access_token.get("users/me", params_token).parsed
75
+ end
76
+
77
+ def params_token
78
+ { params: access_token.to_hash }
79
+ end
80
+
81
+ private
82
+
83
+ def logger
84
+ OmniAuth.logger
85
+ end
86
+
87
+ def raw_info
88
+ @raw_info ||= access_token.get("users/me", params_token).parsed
89
+ end
90
+
91
+ def params_token
92
+ { params: access_token.to_hash }
93
+ end
94
+
95
+ def prune!(hash)
96
+ hash.delete_if do |_, v|
97
+ prune!(v) if v.is_a?(Hash)
98
+ v.nil? || (v.respond_to?(:empty?) && v.empty?)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Mercadopago
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-mercadopago/version"
2
+ require 'omniauth/strategies/mercadopago'
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-mercadopago/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-mercadopago"
8
+ gem.version = OmniAuth::Mercadopago::VERSION
9
+ gem.authors = ["Agustin Cavilliotti"]
10
+ gem.email = ["cavi21@gmail.com"]
11
+
12
+ gem.description = "A MercadoPago strategy for OmniAuth"
13
+ gem.summary = gem.description
14
+ gem.homepage = "https://github.com/cavi21/omniauth-mercadopago"
15
+ gem.license = "MIT"
16
+
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ gem.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
20
+ gem.require_paths = %w(lib)
21
+
22
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.4'
23
+
24
+ gem.add_development_dependency "bundler", "~> 2.0"
25
+ gem.add_development_dependency "rake", "~> 10.0"
26
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift File.expand_path("..", __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+
4
+ if RUBY_VERSION >= "1.9"
5
+ require "simplecov"
6
+ require "coveralls"
7
+
8
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
9
+
10
+ SimpleCov.start do
11
+ minimum_coverage(78.48)
12
+ end
13
+ end
14
+
15
+ require "rspec"
16
+ require "rack/test"
17
+ require "webmock/rspec"
18
+ require "omniauth"
19
+ require "omniauth-mercadopago"
20
+
21
+ RSpec.configure do |config|
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = :expect
24
+ end
25
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
26
+ config.include Rack::Test::Methods
27
+ config.include WebMock::API
28
+ end
@@ -0,0 +1,107 @@
1
+ require "helper"
2
+
3
+ describe OmniAuth::Strategies::Mercadopago do
4
+ def app
5
+ lambda do |_env|
6
+ [200, {}, ["Hello."]]
7
+ end
8
+ end
9
+ let(:fresh_strategy) { Class.new(OmniAuth::Strategies::Mercadopago) }
10
+
11
+ before do
12
+ OmniAuth.config.test_mode = true
13
+ end
14
+
15
+ after do
16
+ OmniAuth.config.test_mode = false
17
+ end
18
+
19
+ describe "Subclassing Behavior" do
20
+ subject { fresh_strategy }
21
+
22
+ it "performs the OmniAuth::Strategy included hook" do
23
+ expect(OmniAuth.strategies).to include(OmniAuth::Strategies::Mercadopago)
24
+ expect(OmniAuth.strategies).to include(subject)
25
+ end
26
+ end
27
+
28
+ describe "#client" do
29
+ subject { fresh_strategy }
30
+
31
+ it "is initialized with symbolized client_options" do
32
+ instance = subject.new(app, :client_options => {"authorize_url" => "https://example.com"})
33
+ expect(instance.client.options[:authorize_url]).to eq("https://example.com")
34
+ end
35
+
36
+ it "sets ssl options as connection options" do
37
+ instance = subject.new(app, :client_options => {"ssl" => {"ca_path" => "foo"}})
38
+ expect(instance.client.options[:connection_opts][:ssl]).to eq(:ca_path => "foo")
39
+ end
40
+ end
41
+
42
+ describe "#authorize_params" do
43
+ subject { fresh_strategy }
44
+
45
+ it "includes any authorize params passed in the :authorize_params option" do
46
+ instance = subject.new("abc", "def", :authorize_params => {:foo => "bar", :baz => "zip"})
47
+ expect(instance.authorize_params["foo"]).to eq("bar")
48
+ expect(instance.authorize_params["baz"]).to eq("zip")
49
+ end
50
+
51
+ it "includes top-level options that are marked as :authorize_options" do
52
+ instance = subject.new("abc", "def", :authorize_options => [:scope, :foo, :state], :scope => "bar", :foo => "baz")
53
+ expect(instance.authorize_params["scope"]).to eq("bar")
54
+ expect(instance.authorize_params["foo"]).to eq("baz")
55
+ end
56
+
57
+ it "includes random state in the authorize params" do
58
+ instance = subject.new("abc", "def")
59
+ expect(instance.authorize_params.keys).to eq(["state"])
60
+ expect(instance.session["omniauth.state"]).not_to be_empty
61
+ end
62
+ end
63
+
64
+ describe "#token_params" do
65
+ subject { fresh_strategy }
66
+
67
+ it "includes any authorize params passed in the :authorize_params option" do
68
+ instance = subject.new("abc", "def", :token_params => {:foo => "bar", :baz => "zip"})
69
+ expect(instance.token_params).to eq("foo" => "bar", "baz" => "zip")
70
+ end
71
+
72
+ it "includes top-level options that are marked as :authorize_options" do
73
+ instance = subject.new("abc", "def", :token_options => [:scope, :foo], :scope => "bar", :foo => "baz")
74
+ expect(instance.token_params).to eq("scope" => "bar", "foo" => "baz")
75
+ end
76
+ end
77
+
78
+ describe "#callback_phase" do
79
+ subject { fresh_strategy }
80
+ it "calls fail with the client error received" do
81
+ instance = subject.new("abc", "def")
82
+ allow(instance).to receive(:request) do
83
+ double("Request", :params => {"error_reason" => "user_denied", "error" => "access_denied"})
84
+ end
85
+
86
+ expect(instance).to receive(:fail!).with("user_denied", anything)
87
+ instance.callback_phase
88
+ end
89
+ end
90
+ end
91
+
92
+ describe OmniAuth::Strategies::Mercadopago::CallbackError do
93
+ let(:error) { Class.new(OmniAuth::Strategies::Mercadopago::CallbackError) }
94
+ describe "#message" do
95
+ subject { error }
96
+ it "includes all of the attributes" do
97
+ instance = subject.new("error", "description", "uri")
98
+ expect(instance.message).to match(/error/)
99
+ expect(instance.message).to match(/description/)
100
+ expect(instance.message).to match(/uri/)
101
+ end
102
+ it "includes all of the attributes" do
103
+ instance = subject.new(nil, :symbol)
104
+ expect(instance.message).to eq("symbol")
105
+ end
106
+ end
107
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-mercadopago
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Agustin Cavilliotti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A MercadoPago strategy for OmniAuth
56
+ email:
57
+ - cavi21@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - lib/omniauth-mercadopago.rb
72
+ - lib/omniauth-mercadopago/version.rb
73
+ - lib/omniauth/strategies/mercadopago.rb
74
+ - omniauth-mercadopago.gemspec
75
+ - spec/helper.rb
76
+ - spec/omniauth/strategies/mercadopago_spec.rb
77
+ homepage: https://github.com/cavi21/omniauth-mercadopago
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A MercadoPago strategy for OmniAuth
101
+ test_files:
102
+ - spec/helper.rb
103
+ - spec/omniauth/strategies/mercadopago_spec.rb