omniauth-traxo 0.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 +7 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/Rakefile +8 -0
- data/lib/omniauth-traxo.rb +2 -0
- data/lib/omniauth-traxo/version.rb +5 -0
- data/lib/omniauth/strategies/traxo.rb +82 -0
- data/omniauth-traxo.gemspec +24 -0
- data/spec/omniauth/strategies/traxo_spec.rb +159 -0
- data/spec/spec_helper.rb +20 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db0cebc462689d2f2a0ed5f79ae200b2349c112e
|
4
|
+
data.tar.gz: 07dc25fd13d9416c03e1548f2aee79055157297a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94ba881c2555f64ae6e7e213f76985d1ec9e8d1d2d9bdbb17e1fa6c7641993cf299ef6c16be1c6b54da84f4b31e5dccc3a48e08ccb8258c24497eb5600e7e84d
|
7
|
+
data.tar.gz: 22500ab158636c7c2e265e4cd4b302ae0ab273a29715b8ba7ae96be9023d2d7c867a7e84065d27c49b2b73201647df1aa901f639f36ef05f8409c7880a6a32ce
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Iuri Madeira
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'omniauth-oauth'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Traxo < OmniAuth::Strategies::OAuth
|
7
|
+
option :name, 'traxo'
|
8
|
+
|
9
|
+
option :client_options,
|
10
|
+
authorize_path: '/oauth/authenticate',
|
11
|
+
site: 'https://api.twitter.com',
|
12
|
+
proxy: ENV['http_proxy'] ? URI(ENV['http_proxy']) : nil
|
13
|
+
|
14
|
+
uid { access_token.params[:user_id] }
|
15
|
+
|
16
|
+
info do
|
17
|
+
{
|
18
|
+
nickname: raw_info['screen_name'],
|
19
|
+
name: raw_info['name'],
|
20
|
+
email: raw_info['email'],
|
21
|
+
location: raw_info['location'],
|
22
|
+
image: image_url,
|
23
|
+
description: raw_info['description'],
|
24
|
+
urls: {
|
25
|
+
'Website' => raw_info['url'],
|
26
|
+
'Traxo' => "https://traxo.com/#{raw_info['screen_name']}"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
extra do
|
32
|
+
skip_info? ? {} : { raw_info: raw_info }
|
33
|
+
end
|
34
|
+
|
35
|
+
def raw_info
|
36
|
+
@raw_info ||= JSON.load(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true&include_email=true').body)
|
37
|
+
rescue ::Errno::ETIMEDOUT
|
38
|
+
raise ::Timeout::Error
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :old_request_phase, :request_phase
|
42
|
+
|
43
|
+
def request_phase
|
44
|
+
%w[force_login lang screen_name].each do |v|
|
45
|
+
if request.params[v]
|
46
|
+
options[:authorize_params][v.to_sym] = request.params[v]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
%w[x_auth_access_type].each do |v|
|
51
|
+
if request.params[v]
|
52
|
+
options[:request_params][v.to_sym] = request.params[v]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if options[:use_authorize] || request.params['use_authorize'] == 'true'
|
57
|
+
options[:client_options][:authorize_path] = '/oauth/authorize'
|
58
|
+
else
|
59
|
+
options[:client_options][:authorize_path] = '/oauth/authenticate'
|
60
|
+
end
|
61
|
+
|
62
|
+
old_request_phase
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def image_url
|
68
|
+
original_url = options[:secure_image_url] ? raw_info['profile_image_url_https'] : raw_info['profile_image_url']
|
69
|
+
case options[:image_size]
|
70
|
+
when 'mini'
|
71
|
+
original_url.sub('normal', 'mini')
|
72
|
+
when 'bigger'
|
73
|
+
original_url.sub('normal', 'bigger')
|
74
|
+
when 'original'
|
75
|
+
original_url.sub('_normal', '')
|
76
|
+
else
|
77
|
+
original_url
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'omniauth-traxo/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'omniauth-traxo'
|
7
|
+
s.version = OmniAuth::Traxo::VERSION
|
8
|
+
s.authors = ['Iuri Madeira']
|
9
|
+
s.email = ['iurimadeira@gmail.com']
|
10
|
+
s.homepage = 'https://github.com/iurimadeira/omniauth-traxo'
|
11
|
+
s.description = %q{OmniAuth strategy for Traxo}
|
12
|
+
s.summary = s.description
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.files.each { |item| s.files.delete(item) if item =~ /omniauth-traxo-[0-9]+\.[0-9]+\.[0-9]+\.gem/ }
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_dependency 'json', '~> 1.3'
|
22
|
+
s.add_dependency 'omniauth-oauth', '~> 1.1'
|
23
|
+
s.add_development_dependency 'bundler', '~> 1.0'
|
24
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::traxo do
|
4
|
+
let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
|
5
|
+
|
6
|
+
subject do
|
7
|
+
args = ['appid', 'secret', @options || {}].compact
|
8
|
+
OmniAuth::Strategies::traxo.new(*args).tap do |strategy|
|
9
|
+
allow(strategy).to receive(:request) {
|
10
|
+
request
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'client options' do
|
16
|
+
it 'should have correct name' do
|
17
|
+
expect(subject.options.name).to eq('traxo')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have correct site' do
|
21
|
+
expect(subject.options.client_options.site).to eq('https://api.traxo.com')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have correct authorize url' do
|
25
|
+
expect(subject.options.client_options.authorize_path).to eq('/oauth/authenticate')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'info' do
|
30
|
+
before do
|
31
|
+
allow(subject).to receive(:raw_info).and_return(raw_info_hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should returns the nickname' do
|
35
|
+
expect(subject.info[:nickname]).to eq(raw_info_hash['screen_name'])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should returns the name' do
|
39
|
+
expect(subject.info[:name]).to eq(raw_info_hash['name'])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should returns the email' do
|
43
|
+
expect(subject.info[:email]).to eq(raw_info_hash['email'])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should returns the location' do
|
47
|
+
expect(subject.info[:location]).to eq(raw_info_hash['location'])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should returns the description' do
|
51
|
+
expect(subject.info[:description]).to eq(raw_info_hash['description'])
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should returns the urls' do
|
55
|
+
expect(subject.info[:urls]['Website']).to eq(raw_info_hash['url'])
|
56
|
+
expect(subject.info[:urls]['traxo']).to eq("https://traxo.com/#{raw_info_hash['screen_name']}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'image_size option' do
|
61
|
+
context 'when user has an image' do
|
62
|
+
it 'should return image with size specified' do
|
63
|
+
@options = { :image_size => 'original' }
|
64
|
+
allow(subject).to receive(:raw_info).and_return(
|
65
|
+
{ 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
66
|
+
)
|
67
|
+
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0.png')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should return bigger image when bigger size specified' do
|
71
|
+
@options = { :image_size => 'bigger' }
|
72
|
+
allow(subject).to receive(:raw_info).and_return(
|
73
|
+
{ 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
74
|
+
)
|
75
|
+
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_bigger.png')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should return secure image with size specified' do
|
79
|
+
@options = { :secure_image_url => 'true', :image_size => 'mini' }
|
80
|
+
allow(subject).to receive(:raw_info).and_return(
|
81
|
+
{ 'profile_image_url_https' => 'https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
82
|
+
)
|
83
|
+
expect(subject.info[:image]).to eq('https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_mini.png')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should return normal image by default' do
|
87
|
+
allow(subject).to receive(:raw_info).and_return(
|
88
|
+
{ 'profile_image_url' => 'http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png' }
|
89
|
+
)
|
90
|
+
expect(subject.info[:image]).to eq('http://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_0_normal.png')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'skip_info option' do
|
96
|
+
context 'when skip info option is enabled' do
|
97
|
+
it 'should not include raw_info in extras hash' do
|
98
|
+
@options = { :skip_info => true }
|
99
|
+
allow(subject).to receive(:raw_info).and_return({:foo => 'bar'})
|
100
|
+
expect(subject.extra[:raw_info]).to eq(nil)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'request_phase' do
|
106
|
+
context 'with no request params set and x_auth_access_type specified' do
|
107
|
+
before do
|
108
|
+
allow(subject).to receive(:request).and_return(
|
109
|
+
double('Request', {:params => {'x_auth_access_type' => 'read'}})
|
110
|
+
)
|
111
|
+
allow(subject).to receive(:old_request_phase).and_return(:whatever)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should not break' do
|
115
|
+
expect { subject.request_phase }.not_to raise_error
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with no request params set and use_authorize options provided" do
|
120
|
+
before do
|
121
|
+
@options = { :use_authorize => true }
|
122
|
+
allow(subject).to receive(:request) do
|
123
|
+
double('Request', {:params => {} })
|
124
|
+
end
|
125
|
+
allow(subject).to receive(:old_request_phase) { :whatever }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should switch authorize_path from authenticate to authorize" do
|
129
|
+
expect { subject.request_phase }.to change { subject.options.client_options.authorize_path }.from('/oauth/authenticate').to('/oauth/authorize')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with no request params set and force_login specified" do
|
134
|
+
before do
|
135
|
+
allow(subject).to receive(:request) do
|
136
|
+
double('Request', {:params => { 'force_login' => true } })
|
137
|
+
end
|
138
|
+
allow(subject).to receive(:old_request_phase) { :whatever }
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should change add force_login=true to authorize_params" do
|
142
|
+
expect { subject.request_phase }.to change {subject.options.authorize_params.force_login}.from(nil).to(true)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def raw_info_hash
|
151
|
+
{
|
152
|
+
'screen_name' => 'foo',
|
153
|
+
'name' => 'Foo Bar',
|
154
|
+
'email' => 'foo@example.com',
|
155
|
+
'location' => 'India',
|
156
|
+
'description' => 'Developer',
|
157
|
+
'url' => 'example.com/foobar'
|
158
|
+
}
|
159
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
minimum_coverage(94.59)
|
6
|
+
end
|
7
|
+
require 'rspec'
|
8
|
+
require 'rack/test'
|
9
|
+
require 'webmock/rspec'
|
10
|
+
require 'omniauth'
|
11
|
+
require 'omniauth-traxo'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include WebMock::API
|
15
|
+
config.include Rack::Test::Methods
|
16
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
17
|
+
config.expect_with :rspec do |c|
|
18
|
+
c.syntax = :expect
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-traxo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Iuri Madeira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description: OmniAuth strategy for Traxo
|
56
|
+
email:
|
57
|
+
- iurimadeira@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE
|
64
|
+
- Rakefile
|
65
|
+
- lib/omniauth-traxo.rb
|
66
|
+
- lib/omniauth-traxo/version.rb
|
67
|
+
- lib/omniauth/strategies/traxo.rb
|
68
|
+
- omniauth-traxo.gemspec
|
69
|
+
- spec/omniauth/strategies/traxo_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
homepage: https://github.com/iurimadeira/omniauth-traxo
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.4.8
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: OmniAuth strategy for Traxo
|
95
|
+
test_files:
|
96
|
+
- spec/omniauth/strategies/traxo_spec.rb
|
97
|
+
- spec/spec_helper.rb
|