omniauth-expressov3 1.0.1 → 1.0.2
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 +8 -8
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/omniauth-expressov3/expressov3_auth_client.rb +2 -1
- data/lib/omniauth-expressov3/jsonrpc_tine_connection.rb +59 -28
- data/lib/omniauth-expressov3/version.rb +1 -1
- data/lib/omniauth/strategies/expressov3.rb +9 -26
- data/spec/omniauth/strategies/expressov3_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzU5ODEyM2M2MWRmNmZjODVjNzg2YTcyMDFmNjE5ZDM0ODM0YjQ2OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWEwNTI0Y2RhYjg0YjkwYjdkNDhlMjQwZTIxMjBlNjkxMDc5NjY0Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjUzNDE4Yzg2ZGIxZmQ0MWY4YTNjM2FlYWFhNmZiNjllYjQ3OTYyZjBjNThi
|
10
|
+
OTYxZmQzZjMzODY5OWEzYjczYTU2MTM2NDRiZjczZTliNjkzYjA2NGFhNjVi
|
11
|
+
NDNkNjQ1ZDg1NzhjYTAxMDljMjU0ODUxZDdjYTJiODdiYTNiZmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGUxMThiODcwMDUyZDNhOGI1ZTVkOTBiOTg2OTczMjcyMjE3YzU5YTRmZTBk
|
14
|
+
ZGIxNWEyYzkxZDM4MDc3MTgxMzJkZWIzOTA2YjhhZjIyZWU4MjRkYjZmZTQ4
|
15
|
+
ODhmNjM0ZWJmMDdmNzI5MWUyNjg3ZGQ5YzUxZjY2NDAxODk0YTM=
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# OmniAuth ExpressoV3
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/omniauth-expressov3)
|
4
3
|
[](https://circleci.com/gh/abner/omniauth-expressov3/tree/master)
|
5
4
|
[](https://codeclimate.com/github/abner/omniauth-expressov3)
|
6
5
|
[](https://codeclimate.com/github/abner/omniauth-expressov3)
|
6
|
+
[](http://badge.fury.io/rb/omniauth-expressov3)
|
7
7
|
|
8
8
|
This gem contains the Expresso strategy for OmniAuth.
|
9
9
|
|
@@ -191,7 +191,7 @@ OmniAuth ExpressoV3 is tested under 1.9.3, 2.0.0, 2.1.0, JRuby, and Rubinius.
|
|
191
191
|
|
192
192
|
Please read the [contribution guidelines](CONTRIBUTING.md) for some information on how to get started. No contribution is too small.
|
193
193
|
|
194
|
-
## License
|
194
|
+
## License
|
195
195
|
|
196
196
|
Copyright (c) 2015 by Ábner Oliveira
|
197
197
|
|
@@ -8,11 +8,12 @@ module OmniAuth
|
|
8
8
|
|
9
9
|
SERVICE_URL = "https://expressov3.serpro.gov.br/index.php"
|
10
10
|
|
11
|
-
|
11
|
+
VALID_ADAPTER_CONFIGURATION_KEYS = [:service_url]
|
12
12
|
|
13
13
|
def initialize(options={})
|
14
14
|
service_url = options['service_url'] || SERVICE_URL
|
15
15
|
@json_tine = JSONRPCTineConnection.new service_url, options['debug']
|
16
|
+
@debug = options['debug']
|
16
17
|
end
|
17
18
|
|
18
19
|
def send(method_name, args={})
|
@@ -36,35 +36,18 @@ module OmniAuth
|
|
36
36
|
(@random.rand * 1000000).to_i
|
37
37
|
end
|
38
38
|
|
39
|
-
def send(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
49
|
-
end
|
50
|
-
response = @http.start {|http| @http.request(@req) }
|
51
|
-
puts "Response #{response.code} #{response.message}: #{response.body}" if @debug
|
52
|
-
@json_return = JSON.parse(response.body)
|
53
|
-
unless @tine_key && @json_key
|
54
|
-
@json_key = @json_return['result']['jsonKey'] if @json_return['result']
|
55
|
-
|
56
|
-
puts "COOKIES: #{response.get_fields('Set-Cookie')}" if @debug
|
57
|
-
@tine_key = response.get_fields('Set-Cookie').to_s.split(';')[0].split('=')[1]
|
39
|
+
def send(tine_method, args=nil)
|
40
|
+
|
41
|
+
response = execute_http_call(tine_method, args)
|
42
|
+
hash_response = parse_response(response)
|
43
|
+
@json_return = hash_response[:json_object]
|
44
|
+
@cookies = hash_response[:cookies]
|
45
|
+
@tine_key = hash_response[:tine_key]
|
46
|
+
@json_key = hash_response[:json_key]
|
47
|
+
@last_body = response.body
|
58
48
|
|
59
|
-
|
60
|
-
cookies_array = Array.new
|
61
|
-
all_cookies.each { | cookie | cookies_array.push(cookie.split('; ')[0]) }
|
62
|
-
@cookies = cookies_array.join('; ')
|
49
|
+
output_debug_response_and_vars(response)
|
63
50
|
|
64
|
-
end
|
65
|
-
puts "TINE_KEY: "+@tine_key if @tine_key and @debug
|
66
|
-
puts "JSON_KEY: "+@json_key if @json_key and @debug
|
67
|
-
@last_body = response.body
|
68
51
|
return response, response.body
|
69
52
|
end
|
70
53
|
|
@@ -99,7 +82,55 @@ module OmniAuth
|
|
99
82
|
@tine_key = nil
|
100
83
|
end
|
101
84
|
|
102
|
-
|
85
|
+
private
|
86
|
+
def execute_http_call(tine_method, args=nil)
|
87
|
+
@req = Net::HTTP::Post.new(@uri.request_uri, initheader = {'Content-Type'=>'application/json'})
|
88
|
+
json_body = {:jsonrpc => '2.0', :method => tine_method, :id => next_cont}
|
89
|
+
json_body.merge!({:params => args}) unless args.nil?
|
90
|
+
@req.body = uri_escape_sanely( json_body.to_json )
|
91
|
+
add_request_fields #headers e cookies
|
92
|
+
unless @http
|
93
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
94
|
+
@http.use_ssl = true
|
95
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
96
|
+
end
|
97
|
+
return @http.start {|http| @http.request(@req) }
|
98
|
+
end
|
99
|
+
|
100
|
+
def parse_response response
|
101
|
+
json = JSON.parse(response.body)
|
102
|
+
|
103
|
+
json_key = json['result']['jsonKey'] if json['result']
|
104
|
+
|
105
|
+
cookies = nil, tine_key = nil
|
106
|
+
|
107
|
+
if response.get_fields('Set-Cookie')
|
108
|
+
tine_key = response.get_fields('Set-Cookie').to_s.split(';')[0].split('=')[1]
|
109
|
+
all_cookies = response.get_fields('set-cookie')
|
110
|
+
cookies_array = Array.new
|
111
|
+
all_cookies.each { | cookie | cookies_array.push(cookie.split('; ')[0]) }
|
112
|
+
cookies = cookies_array.join('; ')
|
113
|
+
end
|
114
|
+
|
115
|
+
return {
|
116
|
+
:json_object => json,
|
117
|
+
:tine_key => (tine_key || @tine_key) ,
|
118
|
+
:json_key => json_key,
|
119
|
+
:cookies => (cookies || @cookies)
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
def output_debug_response_and_vars(response)
|
124
|
+
if @debug
|
125
|
+
puts "Response #{response.code} #{response.message}: #{response.body}"
|
126
|
+
puts "TINE_KEY: "+@tine_key if @tine_key
|
127
|
+
puts "JSON_KEY: "+@json_key if @json_key
|
128
|
+
puts "COOKIES: #{@cookies}" if @cookies
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
protected
|
103
134
|
def add_request_fields
|
104
135
|
#headers sempre enviados
|
105
136
|
@req.add_field 'User-Agent', 'Ruby JSON-RPC Client 2.0'
|
@@ -47,6 +47,7 @@ module OmniAuth
|
|
47
47
|
return fail!(:missing_credentials) if missing_credentials?
|
48
48
|
begin
|
49
49
|
@auth_info = @auth_client.authenticate(request['username'], request['password'])
|
50
|
+
|
50
51
|
return fail!(:invalid_credentials) if !@auth_info
|
51
52
|
|
52
53
|
@expresso_user_info = @auth_client.get_user_data
|
@@ -76,32 +77,14 @@ module OmniAuth
|
|
76
77
|
def self.map_user(mapper, object)
|
77
78
|
user = {}
|
78
79
|
mapper.each do |key, value|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
user[key] = object[value_key][sub_value_key]
|
88
|
-
# puts "HERE: #{key} => #{object[value_key][sub_value_key]}"
|
89
|
-
else
|
90
|
-
user[key] = nil
|
91
|
-
end
|
92
|
-
# puts '--------------------------------------------------'
|
93
|
-
|
94
|
-
when Array
|
95
|
-
value.each {|v| (user[key] = object[v.downcase.to_sym].first; break;) if object.respond_to? v.downcase.to_sym}
|
96
|
-
when Hash
|
97
|
-
value.map do |key1, value1|
|
98
|
-
pattern = key1.dup
|
99
|
-
value1.each_with_index do |v,i|
|
100
|
-
part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1].first; break;) if object.respond_to? v1}
|
101
|
-
pattern.gsub!("%#{i}",part||'')
|
102
|
-
end
|
103
|
-
user[key] = pattern
|
104
|
-
end
|
80
|
+
values_keys = value.split('::')
|
81
|
+
value_key = values_keys[0]
|
82
|
+
sub_value_key = values_keys[1]
|
83
|
+
|
84
|
+
if object && object.has_key?(value_key) && object[value_key] && object[value_key].has_key?(sub_value_key)
|
85
|
+
user[key] = object[value_key][sub_value_key]
|
86
|
+
else
|
87
|
+
user[key] = nil
|
105
88
|
end
|
106
89
|
end
|
107
90
|
user
|
@@ -116,6 +116,22 @@ describe "OmniAuth::Strategies::ExpressoV3" do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
context 'success touching service' do
|
120
|
+
|
121
|
+
before(:each) do
|
122
|
+
OmniAuth::ExpressoV3::AuthClient.unstub(:new)
|
123
|
+
end
|
124
|
+
let(:auth_hash){ last_request.env['omniauth.auth'] }
|
125
|
+
|
126
|
+
it 'should authenticate on expresso v3' do
|
127
|
+
post('/auth/expressov3/callback', {:username => ENV['EXPRESSO_USERNAME'], :password => ENV['EXPRESSO_PASSWORD']})
|
128
|
+
expect(auth_hash.provider).to eq('expressov3')
|
129
|
+
expect(auth_hash.info.account_id).to eq('801294985')
|
130
|
+
expect(auth_hash.info.username).to eq('80129498572')
|
131
|
+
expect(auth_hash.info.email).to eq('abner.oliveira@serpro.gov.br')
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
119
135
|
#
|
120
136
|
context 'success' do
|
121
137
|
let(:auth_hash){ last_request.env['omniauth.auth'] }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-expressov3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abner Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|