omniauth-mercadolibre 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +12 -0
- data/Guardfile +10 -0
- data/MIT-LICENSE +20 -0
- data/README.md +198 -0
- data/Rakefile +25 -0
- data/lib/omniauth-mercadolibre.rb +2 -0
- data/lib/omniauth-mercadolibre/version.rb +5 -0
- data/lib/omniauth/strategies/mercadolibre.rb +80 -0
- data/omniauth-mercadolibre.gemspec +26 -0
- data/omniauth-mercadolibre.sublime-project +9 -0
- data/spec/fixtures/vcr_cassettes/callback_phase.yml +113 -0
- data/spec/fixtures/vcr_cassettes/request_phase.yml +58 -0
- data/spec/omniauth/strategies/mercado_libre_spec.rb +453 -0
- data/spec/spec_helper.rb +15 -0
- data/test/dump/.gitignore +16 -0
- data/test/dump/Gemfile +48 -0
- data/test/dump/README.rdoc +28 -0
- data/test/dump/Rakefile +6 -0
- data/test/dump/app/assets/images/.keep +0 -0
- data/test/dump/app/assets/javascripts/application.js +16 -0
- data/test/dump/app/assets/javascripts/home.js.coffee +3 -0
- data/test/dump/app/assets/stylesheets/application.css +13 -0
- data/test/dump/app/assets/stylesheets/home.css.scss +3 -0
- data/test/dump/app/controllers/application_controller.rb +5 -0
- data/test/dump/app/controllers/concerns/.keep +0 -0
- data/test/dump/app/controllers/home_controller.rb +4 -0
- data/test/dump/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
- data/test/dump/app/helpers/application_helper.rb +2 -0
- data/test/dump/app/helpers/home_helper.rb +2 -0
- data/test/dump/app/mailers/.keep +0 -0
- data/test/dump/app/models/.keep +0 -0
- data/test/dump/app/models/concerns/.keep +0 -0
- data/test/dump/app/models/user.rb +31 -0
- data/test/dump/app/views/home/index.html.erb +7 -0
- data/test/dump/app/views/layouts/application.html.erb +14 -0
- data/test/dump/bin/bundle +3 -0
- data/test/dump/bin/rails +4 -0
- data/test/dump/bin/rake +4 -0
- data/test/dump/config.ru +4 -0
- data/test/dump/config/application.rb +28 -0
- data/test/dump/config/boot.rb +4 -0
- data/test/dump/config/database.yml +25 -0
- data/test/dump/config/environment.rb +5 -0
- data/test/dump/config/environments/development.rb +29 -0
- data/test/dump/config/environments/production.rb +80 -0
- data/test/dump/config/environments/test.rb +36 -0
- data/test/dump/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dump/config/initializers/devise.rb +256 -0
- data/test/dump/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dump/config/initializers/inflections.rb +16 -0
- data/test/dump/config/initializers/mime_types.rb +5 -0
- data/test/dump/config/initializers/secret_token.rb +12 -0
- data/test/dump/config/initializers/session_store.rb +3 -0
- data/test/dump/config/initializers/wrap_parameters.rb +14 -0
- data/test/dump/config/locales/devise.en.yml +59 -0
- data/test/dump/config/locales/en.yml +23 -0
- data/test/dump/config/routes.rb +9 -0
- data/test/dump/db/migrate/20140120110923_devise_create_users.rb +46 -0
- data/test/dump/db/schema.rb +36 -0
- data/test/dump/db/seeds.rb +7 -0
- data/test/dump/lib/assets/.keep +0 -0
- data/test/dump/lib/tasks/.keep +0 -0
- data/test/dump/log/.keep +0 -0
- data/test/dump/public/404.html +58 -0
- data/test/dump/public/422.html +58 -0
- data/test/dump/public/500.html +57 -0
- data/test/dump/public/favicon.ico +0 -0
- data/test/dump/public/robots.txt +5 -0
- data/test/dump/vendor/assets/javascripts/.keep +0 -0
- data/test/dump/vendor/assets/stylesheets/.keep +0 -0
- metadata +215 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f06e4ddde557c63d2d3a2b8234e359157c45dd64
|
4
|
+
data.tar.gz: 214b9c530de8408010a163432b75d9fb808fab2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2db61e129e654df52fd8bf50b3e5ec7dc2fc3bfa11cf0ef216ed3c59b14e9be5085177e623912f65bcd2c13ac4c1bc428a6f24fc0609268f2d1439e75cb1537
|
7
|
+
data.tar.gz: 08cb3c69c9161748278cb693d5a9655b1825079d7b5ae3ad6c1d59f20dac47041c2561871bb38cb5dba0a1bf9d6152a01d1d9de0f14576387a03975b7e6086c2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
omniauth-mercadolibre
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p353
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 2.0.0@omniauth-mercadolibre --create
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Gullit Miranda.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
# OmniAuth MercadoLibre
|
2
|
+
|
3
|
+
This is OmniAuth strategy for authenticating to MercadoLibre. To
|
4
|
+
use it, you'll need to sign up for an OAuth2 Application ID and Secret
|
5
|
+
on the [MercadoLibre Applications Page](http://applications.mercadolivre.com.br).
|
6
|
+
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
Add to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-facebook'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then `bundle install`.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
`OmniAuth::Strategies::MercadoLibre` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
|
20
|
+
|
21
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
25
|
+
provider :mercadolibre, ENV['MERCADOLIBRE_APP_ID'], ENV['MERCADOLIBRE_APP_SECRET']
|
26
|
+
end
|
27
|
+
```
|
28
|
+
## Auth Hash
|
29
|
+
|
30
|
+
Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
|
31
|
+
|
32
|
+
```json
|
33
|
+
{
|
34
|
+
"provider": "mercadolibre",
|
35
|
+
"uid": "12345678",
|
36
|
+
"info": {
|
37
|
+
"username": "gullitmiranda",
|
38
|
+
"email": "gullitmiranda@requestdev.com.br",
|
39
|
+
"first_name": "Gullit",
|
40
|
+
"last_name": "Miranda",
|
41
|
+
"url": "http://perfil.mercadolivre.com.br/gullitmiranda",
|
42
|
+
"name": "Gullit Miranda"
|
43
|
+
},
|
44
|
+
"credentials": {
|
45
|
+
"token": "APP_USR-7835951963654614-012316-4d69c027164dadd1b5829d62cfc733cf__D_J__-12345678",
|
46
|
+
"refresh_token": "TG-52e17bf8e4b0295cf4be2f44",
|
47
|
+
"expires_at": 1390530648,
|
48
|
+
"expires": true
|
49
|
+
},
|
50
|
+
"extra": {
|
51
|
+
"access_token": {
|
52
|
+
"token_type": "bearer",
|
53
|
+
"scope": "offline_access read write",
|
54
|
+
"access_token": "APP_USR-7835951963654614-012316-4d69c027164dadd1b5829d62cfc733cf__D_J__-12345678",
|
55
|
+
"refresh_token": "TG-52e17bf8e4b0295cf4be2f44",
|
56
|
+
"expires_at": 1390530648
|
57
|
+
},
|
58
|
+
"raw_info": {
|
59
|
+
"id": 12345678,
|
60
|
+
"nickname": "gullitmiranda",
|
61
|
+
"registration_date": "2006-06-28T11:32:00.000-04:00",
|
62
|
+
"first_name": "Gullit",
|
63
|
+
"last_name": "Miranda",
|
64
|
+
"country_id": "BR",
|
65
|
+
"email": "gullitmiranda@requestdev.com.br",
|
66
|
+
"identification": {
|
67
|
+
"number": "12345678901"
|
68
|
+
},
|
69
|
+
"address": {
|
70
|
+
"state": "BR-SP",
|
71
|
+
"city": "São Paulo",
|
72
|
+
"address": "Rua onde judas perdeu as botas",
|
73
|
+
"zip_code": "12345678"
|
74
|
+
},
|
75
|
+
"phone": {
|
76
|
+
"area_code": "12",
|
77
|
+
"number": "12345678",
|
78
|
+
"verified": false
|
79
|
+
},
|
80
|
+
"alternative_phone": {
|
81
|
+
"area_code": "12",
|
82
|
+
"number": "12345678"
|
83
|
+
},
|
84
|
+
"user_type": "normal",
|
85
|
+
"tags": [
|
86
|
+
"normal"
|
87
|
+
],
|
88
|
+
"points": -1,
|
89
|
+
"site_id": "MLB",
|
90
|
+
"permalink": "http://perfil.mercadolivre.com.br/gullitmiranda",
|
91
|
+
"shipping_modes": [
|
92
|
+
"custom",
|
93
|
+
"not_specified"
|
94
|
+
],
|
95
|
+
"seller_experience": "NEWBIE",
|
96
|
+
"seller_reputation": {
|
97
|
+
"transactions": {
|
98
|
+
"period": "historic",
|
99
|
+
"total": 0,
|
100
|
+
"completed": 0,
|
101
|
+
"canceled": 0,
|
102
|
+
"ratings": {
|
103
|
+
"positive": 0,
|
104
|
+
"negative": 0,
|
105
|
+
"neutral": 0
|
106
|
+
}
|
107
|
+
}
|
108
|
+
},
|
109
|
+
"buyer_reputation": {
|
110
|
+
"canceled_transactions": 0,
|
111
|
+
"transactions": {
|
112
|
+
"period": "historic",
|
113
|
+
"total": 2,
|
114
|
+
"completed": 0,
|
115
|
+
"canceled": {
|
116
|
+
"total": 2,
|
117
|
+
"paid": 0
|
118
|
+
},
|
119
|
+
"unrated": {
|
120
|
+
"total": 0,
|
121
|
+
"paid": 0
|
122
|
+
},
|
123
|
+
"not_yet_rated": {
|
124
|
+
"total": 0,
|
125
|
+
"paid": 0,
|
126
|
+
"units": 0
|
127
|
+
}
|
128
|
+
}
|
129
|
+
},
|
130
|
+
"status": {
|
131
|
+
"site_status": "active",
|
132
|
+
"list": {
|
133
|
+
"allow": false,
|
134
|
+
"codes": [
|
135
|
+
"identification_pending",
|
136
|
+
"identification_empty_or_invalid_doc_type"
|
137
|
+
],
|
138
|
+
"immediate_payment": {
|
139
|
+
"required": false
|
140
|
+
}
|
141
|
+
},
|
142
|
+
"buy": {
|
143
|
+
"allow": true,
|
144
|
+
"immediate_payment": {
|
145
|
+
"required": false
|
146
|
+
}
|
147
|
+
},
|
148
|
+
"sell": {
|
149
|
+
"allow": true,
|
150
|
+
"immediate_payment": {
|
151
|
+
"required": false
|
152
|
+
}
|
153
|
+
},
|
154
|
+
"billing": {
|
155
|
+
"allow": false,
|
156
|
+
"codes": [
|
157
|
+
"identification_pending",
|
158
|
+
"identification_empty_or_invalid_doc_type"
|
159
|
+
]
|
160
|
+
},
|
161
|
+
"mercadopago_tc_accepted": true,
|
162
|
+
"mercadopago_account_type": "personal",
|
163
|
+
"mercadoenvios": "not_accepted",
|
164
|
+
"immediate_payment": false,
|
165
|
+
"confirmed_email": true
|
166
|
+
},
|
167
|
+
"credit": {
|
168
|
+
"consumed": 0,
|
169
|
+
"credit_level_id": "MLB5"
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
```
|
175
|
+
|
176
|
+
|
177
|
+
## License
|
178
|
+
|
179
|
+
Copyright (c) 2014 Gullit Miranda.
|
180
|
+
|
181
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
182
|
+
a copy of this software and associated documentation files (the
|
183
|
+
"Software"), to deal in the Software without restriction, including
|
184
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
185
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
186
|
+
permit persons to whom the Software is furnished to do so, subject to
|
187
|
+
the following conditions:
|
188
|
+
|
189
|
+
The above copyright notice and this permission notice shall be
|
190
|
+
included in all copies or substantial portions of the Software.
|
191
|
+
|
192
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
193
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
194
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
195
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
196
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
197
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
198
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require "bundler/gem_tasks"
|
10
|
+
|
11
|
+
require 'rdoc/task'
|
12
|
+
desc 'Run RDoc'
|
13
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
14
|
+
rdoc.rdoc_dir = 'rdoc'
|
15
|
+
rdoc.title = 'Omniauth MercadoLibre'
|
16
|
+
rdoc.options << '--line-numbers'
|
17
|
+
rdoc.rdoc_files.include('README.rdoc')
|
18
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rspec/core/rake_task'
|
22
|
+
RSpec::Core::RakeTask.new
|
23
|
+
|
24
|
+
desc 'Run specs'
|
25
|
+
task default: :spec
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class MercadoLibre < OmniAuth::Strategies::OAuth2
|
6
|
+
API_ROOT_URL = ENV["MERCADOLIBRE_API_ROOT_URL" ] || "https://api.mercadolibre.com"
|
7
|
+
AUTH_URL = ENV["MERCADOLIBRE_AUTH_URL" ] || "https://auth.mercadolibre.com/authorization"
|
8
|
+
OAUTH_URL = ENV["MERCADOLIBRE_OAUTH_URL" ] || "https://api.mercadolibre.com/oauth/token"
|
9
|
+
|
10
|
+
option :client_options, {
|
11
|
+
site: API_ROOT_URL,
|
12
|
+
authorize_url: AUTH_URL,
|
13
|
+
token_url: OAUTH_URL
|
14
|
+
}
|
15
|
+
|
16
|
+
def request_phase
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorize_params
|
21
|
+
super.tap do |params|
|
22
|
+
params[:response_type] = "code"
|
23
|
+
params[:client_id] = client.id
|
24
|
+
params[:redirect_uri] ||= callback_url
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_access_token
|
29
|
+
token_params = {
|
30
|
+
:code => request.params['code'],
|
31
|
+
:redirect_uri => callback_url,
|
32
|
+
:client_id => client.id,
|
33
|
+
:client_secret => client.secret,
|
34
|
+
:grant_type => 'authorization_code'
|
35
|
+
}
|
36
|
+
client.get_token(token_params)
|
37
|
+
end
|
38
|
+
|
39
|
+
# data response of api
|
40
|
+
uid { raw_info['id'].to_s }
|
41
|
+
|
42
|
+
info do
|
43
|
+
prune!({
|
44
|
+
username: raw_info['nickname'],
|
45
|
+
email: raw_info['email'],
|
46
|
+
first_name: raw_info['first_name'],
|
47
|
+
last_name: raw_info['last_name'],
|
48
|
+
image: raw_info['logo'],
|
49
|
+
url: raw_info['permalink']
|
50
|
+
})
|
51
|
+
end
|
52
|
+
|
53
|
+
extra do
|
54
|
+
hash = {}
|
55
|
+
hash[:access_token] = access_token.to_hash
|
56
|
+
hash[:raw_info] = raw_info unless skip_info?
|
57
|
+
prune! hash
|
58
|
+
end
|
59
|
+
|
60
|
+
def raw_info
|
61
|
+
@raw_info ||= access_token.get("users/me", params_token).parsed
|
62
|
+
end
|
63
|
+
|
64
|
+
def params_token
|
65
|
+
{ params: access_token.to_hash }
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def prune!(hash)
|
71
|
+
hash.delete_if do |_, v|
|
72
|
+
prune!(v) if v.is_a?(Hash)
|
73
|
+
v.nil? || (v.respond_to?(:empty?) && v.empty?)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
OmniAuth.config.add_camelization 'mercadolibre', 'MercadoLibre'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Maintain your gem's version:
|
2
|
+
require File.expand_path(File.join('..', 'lib', 'omniauth-mercadolibre', 'version'), __FILE__)
|
3
|
+
|
4
|
+
# Describe your gem and declare its dependencies:
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "omniauth-mercadolibre"
|
7
|
+
gem.version = OmniAuth::MercadoLibre::VERSION
|
8
|
+
|
9
|
+
gem.authors = ["Gullit Miranda"]
|
10
|
+
gem.email = ["gullitmiranda@requestdev.com.br"]
|
11
|
+
gem.description = %q{A MercadoLibre OAuth2 strategy for OmniAuth 1.x}
|
12
|
+
gem.summary = %q{A MercadoLibre OAuth2 strategy for OmniAuth 1.x}
|
13
|
+
gem.homepage = "https://github.com/gullitmiranda/omniauth-mercadolibre"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
21
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1', '>= 1.1.2'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
|
23
|
+
gem.add_development_dependency 'rack-test', '~> 0'
|
24
|
+
gem.add_development_dependency 'simplecov', '~> 0'
|
25
|
+
gem.add_development_dependency 'webmock', '~> 0'
|
26
|
+
end
|