omniauth-expressov3 1.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 +15 -0
- data/.gitignore +3 -0
- data/CONTRIBUTING.md +40 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +99 -0
- data/LICENSE +22 -0
- data/README.md +202 -0
- data/lib/omniauth-expressov3.rb +4 -0
- data/lib/omniauth-expressov3/expressov3_auth_client.rb +77 -0
- data/lib/omniauth-expressov3/jsonrpc_tine_connection.rb +207 -0
- data/lib/omniauth-expressov3/version.rb +5 -0
- data/lib/omniauth/strategies/expressov3.rb +119 -0
- data/omniauth-expressov3.gemspec +24 -0
- data/spec/omniauth-expressov3/expressov3_auth_client_2_spec.rb +17 -0
- data/spec/omniauth/strategies/expressov3_spec.rb +162 -0
- data/spec/result.json +121 -0
- data/spec/spec_helper.rb +18 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzJhMmJjYjMxMTZiNjUxNzFmMGZhYzJiZWY0NDY4NGJlNTkzMzI5NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTY1YTQ0NmM2ODk5ZTkzNzM3NzBkMmZjMDU4YTU3NGY4NGZiMmFhOQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjFmNTJiNmI1MjExMmMyZTk4MjU0MTI2NTRiZmM0OGEwMjM0MDY3ZWY1NDIy
|
10
|
+
OTI5ZmJlOTBkY2U5ZGE1NTYwZDEzNGNmZmMyYjliY2Q3NWYwZWExYTVmZDRj
|
11
|
+
M2YzMTdiNDE0OTMxNjY5YzgzYTZiNTA0ODYxZDQ0YTc2MGExMWQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTNiZjFhNTVjMTM0ZjI4Y2M5YjQzM2NkZThmNjRjYjU4Njk4Nzc3M2VmNWQw
|
14
|
+
MDc5N2M5MzlkNDZkMGYyM2UyNTllZWM1MmM1ODVhMWZhZTdiODBkNDgxZGNi
|
15
|
+
ZDc4ZjU3MjgwN2Q1N2MzNjFlYmQyYzlmNDIyOTcxOTlkMjNmZTM=
|
data/.gitignore
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
For the best chance of having your changes merged, please:
|
4
|
+
|
5
|
+
* Fork the project.
|
6
|
+
|
7
|
+
* Make your feature addition or bug fix.
|
8
|
+
|
9
|
+
* Add tests for it. This is important so it is not accidentally broken in a future version.
|
10
|
+
|
11
|
+
* Commit, do not mess with rakefile, version, or history. (If you want to have your own version, that is fine but bump version in a commit by itself so it can be ignored when pulled).
|
12
|
+
|
13
|
+
* Send a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
If your proposed changes only affect documentation, include the following on a
|
16
|
+
new line in each of your commit messages:
|
17
|
+
|
18
|
+
```
|
19
|
+
[ci skip]
|
20
|
+
```
|
21
|
+
|
22
|
+
This will signal [Travis](https://travis-ci.org) that running the test suite is
|
23
|
+
not necessary for these changes.
|
24
|
+
|
25
|
+
# Reporting Bugs
|
26
|
+
|
27
|
+
If you are experiencing unexpected behavior and, after having read [omniauth](https://github.com/intridea/omniauth) and [omniauth-expressov3](https://github.com/abner/omniauth-expressov3)'s documentation, are convinced this behavior is a bug, please:
|
28
|
+
|
29
|
+
1. [Search](https://github.com/abner/omniauth-expressov3/issues) existing issues.
|
30
|
+
2. Collect enough information to reproduce the issue:
|
31
|
+
|
32
|
+
* omniauth-expressov3 version
|
33
|
+
|
34
|
+
* Ruby version
|
35
|
+
|
36
|
+
* Specific setup conditions
|
37
|
+
|
38
|
+
* Description of expected behavior
|
39
|
+
|
40
|
+
* Description of actual behavior
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-expressov3 (1.0)
|
5
|
+
omniauth (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
awesome_print (1.6.1)
|
11
|
+
celluloid (0.16.0)
|
12
|
+
timers (~> 4.0.0)
|
13
|
+
coderay (1.1.0)
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
docile (1.1.5)
|
16
|
+
ffi (1.9.6)
|
17
|
+
formatador (0.2.5)
|
18
|
+
growl (1.0.3)
|
19
|
+
guard (2.12.1)
|
20
|
+
formatador (>= 0.2.4)
|
21
|
+
listen (~> 2.7)
|
22
|
+
lumberjack (~> 1.0)
|
23
|
+
nenv (~> 0.1)
|
24
|
+
notiffany (~> 0.0)
|
25
|
+
pry (>= 0.9.12)
|
26
|
+
shellany (~> 0.0)
|
27
|
+
thor (>= 0.18.1)
|
28
|
+
guard-bundler (2.1.0)
|
29
|
+
bundler (~> 1.0)
|
30
|
+
guard (~> 2.2)
|
31
|
+
guard-compat (~> 1.1)
|
32
|
+
guard-compat (1.2.1)
|
33
|
+
guard-rspec (4.5.0)
|
34
|
+
guard (~> 2.1)
|
35
|
+
guard-compat (~> 1.1)
|
36
|
+
rspec (>= 2.99.0, < 4.0)
|
37
|
+
hashie (3.4.0)
|
38
|
+
hitimes (1.2.2)
|
39
|
+
listen (2.8.5)
|
40
|
+
celluloid (>= 0.15.2)
|
41
|
+
rb-fsevent (>= 0.9.3)
|
42
|
+
rb-inotify (>= 0.9)
|
43
|
+
lumberjack (1.0.9)
|
44
|
+
maruku (0.7.2)
|
45
|
+
method_source (0.8.2)
|
46
|
+
multi_json (1.10.1)
|
47
|
+
nenv (0.2.0)
|
48
|
+
notiffany (0.0.4)
|
49
|
+
nenv (~> 0.1)
|
50
|
+
shellany (~> 0.0)
|
51
|
+
omniauth (1.2.2)
|
52
|
+
hashie (>= 1.2, < 4)
|
53
|
+
rack (~> 1.0)
|
54
|
+
pry (0.10.1)
|
55
|
+
coderay (~> 1.1.0)
|
56
|
+
method_source (~> 0.8.1)
|
57
|
+
slop (~> 3.4)
|
58
|
+
rack (1.6.0)
|
59
|
+
rack-test (0.6.3)
|
60
|
+
rack (>= 1.0)
|
61
|
+
rake (0.9.6)
|
62
|
+
rb-fsevent (0.9.4)
|
63
|
+
rb-inotify (0.9.5)
|
64
|
+
ffi (>= 0.5.0)
|
65
|
+
rspec (2.99.0)
|
66
|
+
rspec-core (~> 2.99.0)
|
67
|
+
rspec-expectations (~> 2.99.0)
|
68
|
+
rspec-mocks (~> 2.99.0)
|
69
|
+
rspec-core (2.99.2)
|
70
|
+
rspec-expectations (2.99.2)
|
71
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
72
|
+
rspec-mocks (2.99.3)
|
73
|
+
shellany (0.0.1)
|
74
|
+
simplecov (0.9.1)
|
75
|
+
docile (~> 1.1.0)
|
76
|
+
multi_json (~> 1.0)
|
77
|
+
simplecov-html (~> 0.8.0)
|
78
|
+
simplecov-html (0.8.0)
|
79
|
+
slop (3.6.0)
|
80
|
+
thor (0.19.1)
|
81
|
+
timers (4.0.1)
|
82
|
+
hitimes
|
83
|
+
|
84
|
+
PLATFORMS
|
85
|
+
ruby
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
awesome_print
|
89
|
+
growl
|
90
|
+
guard
|
91
|
+
guard-bundler
|
92
|
+
guard-rspec
|
93
|
+
maruku (~> 0.6)
|
94
|
+
omniauth-expressov3!
|
95
|
+
rack-test (~> 0.5)
|
96
|
+
rake (~> 0.8)
|
97
|
+
rb-fsevent
|
98
|
+
rspec (~> 2.7)
|
99
|
+
simplecov (~> 0.4)
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 SerproLivre
|
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/README.md
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
# OmniAuth Twitter
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/omniauth-twitter)
|
4
|
+
[](https://circleci.com/gh/abner/omniauth-expressov3/tree/master)
|
5
|
+
[](https://codeclimate.com/github/abner/omniauth-expressov3)
|
6
|
+
[](https://codeclimate.com/github/abner/omniauth-expressov3)
|
7
|
+
|
8
|
+
This gem contains the Expresso strategy for OmniAuth.
|
9
|
+
|
10
|
+
## Before You Begin
|
11
|
+
|
12
|
+
You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started.
|
13
|
+
|
14
|
+
|
15
|
+
## Using This Strategy
|
16
|
+
|
17
|
+
First start by adding this gem to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'omniauth-expressov3'
|
21
|
+
```
|
22
|
+
|
23
|
+
If you need to use the latest HEAD version, you can do so with:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'omniauth-expressov3', :github => 'abner/omniauth-expressov3'
|
27
|
+
```
|
28
|
+
|
29
|
+
Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
33
|
+
provider :expressov3
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
## Authentication Hash
|
39
|
+
An example auth hash available in `request.env['omniauth.auth']`:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
{
|
43
|
+
"provider" => "expressov3",
|
44
|
+
"uid" => nil,
|
45
|
+
"info" => {
|
46
|
+
"account_id" => "111111111",
|
47
|
+
"contact_id" => "contact_id",
|
48
|
+
"username" => "11111111111",
|
49
|
+
"name" => "Joao Ninguem",
|
50
|
+
"first_name" => "Joao",
|
51
|
+
"last_name" => "Ninguem",
|
52
|
+
"email" => "joao.ninguem@serpro.gov.br",
|
53
|
+
"telephone" => "(71)1111-1111",
|
54
|
+
"organization_unit" => "SUPDE/DESDR/DE5CT",
|
55
|
+
"tine_key" => "tine_key",
|
56
|
+
"json_key" => "json_key"
|
57
|
+
},
|
58
|
+
"credentials" => {},
|
59
|
+
"extra" => {
|
60
|
+
"raw_info" => {
|
61
|
+
"keys" => {
|
62
|
+
"tine_key" => "tine_key",
|
63
|
+
"json_key" => "json_key"
|
64
|
+
},
|
65
|
+
"currentAccount" => {
|
66
|
+
"accountId" => "111111111",
|
67
|
+
"accountLoginName" => "11111111111",
|
68
|
+
"accountLastLogin" => "2015-02-10 13:42:15",
|
69
|
+
"accountLastLoginfrom" => "161.148.31.232",
|
70
|
+
"accountLastPasswordChange" => "2015-01-05 11:48:58",
|
71
|
+
"accountStatus" => "enabled",
|
72
|
+
"accountExpires" => nil,
|
73
|
+
"accountPrimaryGroup" => "888",
|
74
|
+
"accountHomeDirectory" => "/home/11111111111",
|
75
|
+
"accountLoginShell" => "/bin/bash",
|
76
|
+
"accountDisplayName" => "Joao Ninguem",
|
77
|
+
"accountFullName" => "Joao Ninguem",
|
78
|
+
"accountFirstName" => "Joao",
|
79
|
+
"accountLastName" => "Ninguem",
|
80
|
+
"accountEmailAddress" => "joao.ninguem@serpro.gov.br",
|
81
|
+
"lastLoginFailure" => "2014-06-13 11:59:25",
|
82
|
+
"loginFailures" => 0,
|
83
|
+
"contact_id" => "contact_id",
|
84
|
+
"openid" => nil,
|
85
|
+
"visibility" => "displayed",
|
86
|
+
"container_id" => 1,
|
87
|
+
"imapUser" => {
|
88
|
+
"emailMailQuota" => 500,
|
89
|
+
"emailMailSize" => 435,
|
90
|
+
"emailUserId" => "11111111111",
|
91
|
+
"emailForwardOnly" => 0,
|
92
|
+
"emailUsername" => "11111111111"
|
93
|
+
},
|
94
|
+
"emailUser" => {
|
95
|
+
"emailForwards" => [],
|
96
|
+
"emailForwardOnly" => false,
|
97
|
+
"emailAliases" => [
|
98
|
+
[0] "joao.ninguem@mail.serpro.gov.br"
|
99
|
+
],
|
100
|
+
"emailAddress" => "joao.ninguem@serpro.gov.br"
|
101
|
+
},
|
102
|
+
"accountPasswordExpired" => "no",
|
103
|
+
"accountDN" => "ou=reg,ou=regsdr,dc=serpro,dc=gov,dc=br",
|
104
|
+
"smtpUser" => {
|
105
|
+
"emailForwards" => [],
|
106
|
+
"emailForwardOnly" => false,
|
107
|
+
"emailAliases" => [
|
108
|
+
[0] "joao.ninguem@mail.serpro.gov.br"
|
109
|
+
],
|
110
|
+
"emailAddress" => "joao.ninguem@serpro.gov.br"
|
111
|
+
}
|
112
|
+
},
|
113
|
+
"userContact" => {
|
114
|
+
"id" => "contact_id",
|
115
|
+
"adr_one_countryname" => "",
|
116
|
+
"adr_one_locality" => nil,
|
117
|
+
"adr_one_postalcode" => nil,
|
118
|
+
"adr_one_region" => nil,
|
119
|
+
"adr_one_street" => nil,
|
120
|
+
"adr_one_street2" => nil,
|
121
|
+
"adr_one_lon" => nil,
|
122
|
+
"adr_one_lat" => nil,
|
123
|
+
"adr_two_countryname" => "",
|
124
|
+
"adr_two_locality" => nil,
|
125
|
+
"adr_two_postalcode" => nil,
|
126
|
+
"adr_two_region" => nil,
|
127
|
+
"adr_two_street" => nil,
|
128
|
+
"adr_two_street2" => nil,
|
129
|
+
"adr_two_lon" => nil,
|
130
|
+
"adr_two_lat" => nil,
|
131
|
+
"assistent" => nil,
|
132
|
+
"bday" => nil,
|
133
|
+
"calendar_uri" => nil,
|
134
|
+
"email" => "joao.ninguem@serpro.gov.br",
|
135
|
+
"email_home" => "",
|
136
|
+
"freebusy_uri" => nil,
|
137
|
+
"geo" => nil,
|
138
|
+
"note" => nil,
|
139
|
+
"container_id" => 1,
|
140
|
+
"pubkey" => nil,
|
141
|
+
"role" => nil,
|
142
|
+
"room" => nil,
|
143
|
+
"salutation" => nil,
|
144
|
+
"title" => nil,
|
145
|
+
"tz" => nil,
|
146
|
+
"url" => "",
|
147
|
+
"url_home" => "",
|
148
|
+
"n_fn" => "Joao Ninguem",
|
149
|
+
"n_fileas" => "Joao Ninguem",
|
150
|
+
"n_family" => "Ninguem",
|
151
|
+
"n_given" => "Joao",
|
152
|
+
"n_middle" => nil,
|
153
|
+
"n_prefix" => nil,
|
154
|
+
"n_suffix" => nil,
|
155
|
+
"org_name" => nil,
|
156
|
+
"org_unit" => "SUPDE/DESDR/DE5CT",
|
157
|
+
"tel_assistent" => nil,
|
158
|
+
"tel_car" => nil,
|
159
|
+
"tel_cell" => "(71)1111-1111",
|
160
|
+
"tel_cell_private" => nil,
|
161
|
+
"tel_fax" => nil,
|
162
|
+
"tel_fax_home" => nil,
|
163
|
+
"tel_home" => nil,
|
164
|
+
"tel_other" => nil,
|
165
|
+
"tel_pager" => nil,
|
166
|
+
"tel_prefer" => nil,
|
167
|
+
"tel_work" => "(71)1111-1111",
|
168
|
+
"created_by" => nil,
|
169
|
+
"creation_time" => "2013-07-16 21:36:04",
|
170
|
+
"last_modified_by" => nil,
|
171
|
+
"last_modified_time" => nil,
|
172
|
+
"is_deleted" => "0",
|
173
|
+
"deleted_by" => nil,
|
174
|
+
"deleted_time" => nil,
|
175
|
+
"seq" => 0,
|
176
|
+
"type" => "user",
|
177
|
+
"jpegphoto" => 1,
|
178
|
+
"account_id" => "111111111"
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
```
|
185
|
+
|
186
|
+
## Supported Rubies
|
187
|
+
|
188
|
+
OmniAuth ExpressoV3 is tested under 1.9.3, 2.0.0, 2.1.0, JRuby, and Rubinius.
|
189
|
+
|
190
|
+
## Contributing
|
191
|
+
|
192
|
+
Please read the [contribution guidelines](CONTRIBUTING.md) for some information on how to get started. No contribution is too small.
|
193
|
+
|
194
|
+
## License
|
195
|
+
|
196
|
+
Copyright (c) 2015 by Ábner Oliveira
|
197
|
+
|
198
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
199
|
+
|
200
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
201
|
+
|
202
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module ExpressoV3
|
3
|
+
class AuthClient
|
4
|
+
|
5
|
+
class MissingArgumentsError < StandardError; end
|
6
|
+
class AuthenticationError < StandardError; end
|
7
|
+
class ConnectionError < StandardError; end
|
8
|
+
|
9
|
+
SERVICE_URL = "https://expressov3.serpro.gov.br/index.php"
|
10
|
+
|
11
|
+
# VALID_ADAPTER_CONFIGURATION_KEYS = [:service_url]
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
service_url = options['service_url'] || SERVICE_URL
|
15
|
+
@json_tine = JSONRPCTineConnection.new service_url, options['debug']
|
16
|
+
end
|
17
|
+
|
18
|
+
def send(method_name, args={})
|
19
|
+
@json_tine.send(method_name, args)
|
20
|
+
@json_tine.result
|
21
|
+
end
|
22
|
+
|
23
|
+
def authenticate(username, password)
|
24
|
+
validate_arguments(username, password)
|
25
|
+
auth_params = {"user" => username,"password" => password}
|
26
|
+
|
27
|
+
@json_tine.send 'Tinebase.login', auth_params
|
28
|
+
|
29
|
+
# check if user is authenticated, raises an authentication if not
|
30
|
+
validate_login(@json_tine.result)
|
31
|
+
#return user data
|
32
|
+
@json_tine.result
|
33
|
+
end
|
34
|
+
|
35
|
+
def send method, args=nil
|
36
|
+
@json_tine.send method, args
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_user_data
|
40
|
+
#request to get user data
|
41
|
+
@json_tine.send 'Tinebase.getAllRegistryData'
|
42
|
+
#hash with user data
|
43
|
+
{ 'keys' => @json_tine.result['keys'],
|
44
|
+
'currentAccount' => @json_tine.result['Tinebase']['currentAccount'],
|
45
|
+
'userContact' => @json_tine.result['Tinebase']['userContact']
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def last_raw_data
|
50
|
+
@json_tine.last_body
|
51
|
+
end
|
52
|
+
|
53
|
+
def close
|
54
|
+
@json_tine.close if @json_tine
|
55
|
+
end
|
56
|
+
protected
|
57
|
+
|
58
|
+
def validate_arguments(username, password)
|
59
|
+
if username.nil? or password.nil?
|
60
|
+
raise MissingArgumentsError.new('missing credentials arguments')
|
61
|
+
end
|
62
|
+
if "".eql?(username) or "".eql?(password)
|
63
|
+
raise MissingArgumentsError.new('missing credentials arguments')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def validate_login(response_result)
|
68
|
+
authenticated = false
|
69
|
+
authentication_failure_msg = ""
|
70
|
+
if response_result
|
71
|
+
authenticated = response_result['success']
|
72
|
+
end
|
73
|
+
raise AuthenticationError.new(authentication_failure_msg) unless authenticated
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'json'
|
4
|
+
module OmniAuth
|
5
|
+
module ExpressoV3
|
6
|
+
#classe para fazer a conexão com o expresso3/tine20
|
7
|
+
class JSONRPCTineConnection
|
8
|
+
OUR_UNSAFE = /[^ _\.!~*'()a-zA-Z\d;\/?:@&=+$,{}\"-]/nm unless defined?(OUR_UNSAFE)
|
9
|
+
@req = nil
|
10
|
+
@uri = nil
|
11
|
+
@host = nil
|
12
|
+
@port = nil
|
13
|
+
@json_return
|
14
|
+
@json_key = nil
|
15
|
+
@tine_key = nil
|
16
|
+
@debug = false
|
17
|
+
|
18
|
+
|
19
|
+
def initialize(uri, debug = false)
|
20
|
+
@uri = URI.parse(uri)
|
21
|
+
@host = @uri.host
|
22
|
+
@port = @uri.port
|
23
|
+
@debug = debug
|
24
|
+
@http = nil
|
25
|
+
@random = Random.new(Time.new.to_i)
|
26
|
+
@cont = 0
|
27
|
+
@last_body = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def next_cont
|
31
|
+
@cont += 1
|
32
|
+
@cont
|
33
|
+
end
|
34
|
+
|
35
|
+
def next_random
|
36
|
+
(@random.rand * 1000000).to_i
|
37
|
+
end
|
38
|
+
|
39
|
+
def send(method, args=nil)
|
40
|
+
@req = Net::HTTP::Post.new(@uri.request_uri, initheader = {'Content-Type'=>'application/json'})
|
41
|
+
json_body = {:jsonrpc => '2.0', :method => method, :id => next_cont}
|
42
|
+
json_body.merge!({:params => args}) unless args.nil?
|
43
|
+
@req.body = uri_escape_sanely( json_body.to_json )
|
44
|
+
add_request_fields #headers e cookies
|
45
|
+
unless @http
|
46
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
47
|
+
@http.use_ssl = true
|
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]
|
58
|
+
|
59
|
+
all_cookies = response.get_fields('set-cookie')
|
60
|
+
cookies_array = Array.new
|
61
|
+
all_cookies.each { | cookie | cookies_array.push(cookie.split('; ')[0]) }
|
62
|
+
@cookies = cookies_array.join('; ')
|
63
|
+
|
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
|
+
return response, response.body
|
69
|
+
end
|
70
|
+
|
71
|
+
def last_json_object
|
72
|
+
@json_return
|
73
|
+
end
|
74
|
+
|
75
|
+
def last_body
|
76
|
+
@last_body
|
77
|
+
end
|
78
|
+
|
79
|
+
def result
|
80
|
+
if @json_return['result']
|
81
|
+
keys.merge(@json_return['result'])
|
82
|
+
else
|
83
|
+
keys.merge(@json_return)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def keys
|
88
|
+
{
|
89
|
+
'keys' => {'tine_key' => @tine_key, 'json_key' => @json_key}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def close
|
94
|
+
@req = nil
|
95
|
+
@uri = nil
|
96
|
+
@host = nil
|
97
|
+
@port = nil
|
98
|
+
@json_key = nil
|
99
|
+
@tine_key = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
protected
|
103
|
+
def add_request_fields
|
104
|
+
#headers sempre enviados
|
105
|
+
@req.add_field 'User-Agent', 'Ruby JSON-RPC Client 2.0'
|
106
|
+
@req.add_field 'Accept',
|
107
|
+
#
|
108
|
+
#
|
109
|
+
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
|
110
|
+
@req.add_field 'Content-Type', 'application/json; charset=UTF-8'
|
111
|
+
@req.add_field 'X-Tine20-Request-Type', 'JSON'
|
112
|
+
#
|
113
|
+
#header e cookie enviados pelo usuario logado
|
114
|
+
@req.add_field 'X-Tine20-JsonKey', @json_key if @json_key
|
115
|
+
#@req.add_field 'Cookie', 'TINE20SESSID='+@tine_key if @tine_key
|
116
|
+
@req.add_field 'Cookie', @cookies if @cookies
|
117
|
+
end
|
118
|
+
|
119
|
+
def uri_escape_sanely(str)
|
120
|
+
URI.escape(str, OUR_UNSAFE).gsub('%5B', '[').gsub('%5D', ']') # Ruby's regexes are BRAIN-DEAD.
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# def type(msg)
|
128
|
+
# sleep 1 #pausa para poder ler
|
129
|
+
# puts msg
|
130
|
+
# sleep 2 #pausa para observar os resultados
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
#
|
134
|
+
# type "### Abrindo conexao com o servidor do expresso3/tine20"
|
135
|
+
# json_tine = JSONRPCTineConnection.new "https://expressov3.serpro.gov.br/index.php"
|
136
|
+
# #
|
137
|
+
# #
|
138
|
+
# #type "### Listando metodos do usuario nao logado ###"
|
139
|
+
# #response, body = json_tine.send nil, '1'
|
140
|
+
# #
|
141
|
+
# #
|
142
|
+
# type "### Efetuando login ###"
|
143
|
+
# #
|
144
|
+
# #
|
145
|
+
# auth_params = {"user" => 'CPF_AQUI',"password" => 'SENHA AQUI'}
|
146
|
+
# response, body = json_tine.send 'Tinebase.login', '2', auth_params
|
147
|
+
#
|
148
|
+
# #auth_params = {"user" => 'CPF_AQUI',"password" => 'SENHA_AQUI'}
|
149
|
+
# #response, body = json_tine.send 'Tinebase.authenticate', '1', auth_params
|
150
|
+
#
|
151
|
+
#
|
152
|
+
# #type "### Listando metodos do usuario logado ###"
|
153
|
+
# #response, body = json_tine.send nil, '1'
|
154
|
+
#
|
155
|
+
# #type "### Listando dados do usuario logado ###"
|
156
|
+
# #response, body = json_tine.send 'Tinebase.getRegistryData', '1'
|
157
|
+
# response, body = json_tine.send 'Tinebase.getAllRegistryData', '2'
|
158
|
+
# #raise json_tine.result['Expressomail'].keys.inspect
|
159
|
+
#
|
160
|
+
# @level = 0
|
161
|
+
#
|
162
|
+
# @parents = []
|
163
|
+
#
|
164
|
+
# def print_k(hash, f, level=0, parent='')
|
165
|
+
# @parents << parent if level > 0
|
166
|
+
# hash.keys.each do |k|
|
167
|
+
# f.write("\t" * @level + '-' + k + "(" + @parents.join('/') + ")" + "\n")
|
168
|
+
# if(hash[k].respond_to?(:keys))
|
169
|
+
# @level += 1
|
170
|
+
# print_k(hash[k], f, @level, k)
|
171
|
+
# end
|
172
|
+
# end
|
173
|
+
# @level -= 1 if(@level > 0)
|
174
|
+
# @parents.delete(parent)
|
175
|
+
# end
|
176
|
+
#
|
177
|
+
# f = File.open('/tmp/st.txt', 'w+')
|
178
|
+
# print_k(json_tine.last_json_object,f)
|
179
|
+
# f.close
|
180
|
+
#
|
181
|
+
# body2 = {
|
182
|
+
# :currentAccount => json_tine.result['Tinebase']['currentAccount'],
|
183
|
+
# :userContact => json_tine.result['Tinebase']['userContact']
|
184
|
+
# }
|
185
|
+
#
|
186
|
+
#
|
187
|
+
# #type "### Pesquisando contatos ###"
|
188
|
+
# #response, body = json_tine.send 'Addressbook.searchContacts', '10'
|
189
|
+
# #
|
190
|
+
# #
|
191
|
+
# #type "### Carregando mensagens ###"
|
192
|
+
# #
|
193
|
+
#
|
194
|
+
# #params = {"filter"=>{"field"=>"flags","operator"=>"in","value"=>"\\Flagged"},
|
195
|
+
# # "paging"=>{"sort"=>"received","dir"=>"DESC","start"=>0,"limit"=>5}}
|
196
|
+
# #response, body = json_tine.send 'Felamimail.searchMessages', '21', params
|
197
|
+
# #response, body = json_tine.send 'Felamimail.getRegistryData', '21', params
|
198
|
+
#
|
199
|
+
#
|
200
|
+
# File.open('/tmp/dados_abner.json', 'w+') do |f|
|
201
|
+
# f.write body2
|
202
|
+
# end
|
203
|
+
#
|
204
|
+
# exit 0
|
205
|
+
#
|
206
|
+
# #type "### Listando metodos do usuario logado ###"
|
207
|
+
# #response, body = json_tine.send , '1'
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class ExpressoV3
|
7
|
+
include OmniAuth::Strategy
|
8
|
+
|
9
|
+
@@config = {
|
10
|
+
:account_id => 'currentAccount::accountId',
|
11
|
+
:contact_id => 'userContact::id',
|
12
|
+
:username => 'currentAccount::accountLoginName',
|
13
|
+
:name => 'currentAccount::accountFullName',
|
14
|
+
:first_name => 'currentAccount::accountFirstName',
|
15
|
+
:last_name => 'currentAccount::accountLastName',
|
16
|
+
:email => 'currentAccount::accountEmailAddress',
|
17
|
+
:telephone => 'userContact::tel_work',
|
18
|
+
:organization_unit => 'userContact::org_unit',
|
19
|
+
:tine_key => 'keys::tine_key',
|
20
|
+
:json_key => 'keys::json_key'
|
21
|
+
}
|
22
|
+
|
23
|
+
option :title, "Autenticação Expresso V3" #default title for authentication form
|
24
|
+
|
25
|
+
option :name, 'expressov3'
|
26
|
+
option :fields, [:name, :email]
|
27
|
+
|
28
|
+
option :service_url => OmniAuth::ExpressoV3::AuthClient::SERVICE_URL
|
29
|
+
|
30
|
+
# option :on_login, nil
|
31
|
+
# option :on_registration, nil
|
32
|
+
# option :on_failed_registration, nil
|
33
|
+
# option :locate_conditions, lambda{|req| {model.auth_key => req['auth_key']} }
|
34
|
+
|
35
|
+
def request_phase
|
36
|
+
#OmniAuth::Expressov3::AuthClient.validate @options
|
37
|
+
f = OmniAuth::Form.new(:title => (options[:title] || "Autenticação Expresso "), :url => callback_path)
|
38
|
+
f.text_field 'Login', 'username'
|
39
|
+
f.password_field 'Password', 'password'
|
40
|
+
f.button "Sign In"
|
41
|
+
f.to_response
|
42
|
+
end
|
43
|
+
|
44
|
+
def callback_phase
|
45
|
+
@auth_client = OmniAuth::ExpressoV3::AuthClient.new @options, true
|
46
|
+
|
47
|
+
return fail!(:missing_credentials) if missing_credentials?
|
48
|
+
begin
|
49
|
+
@auth_info = @auth_client.authenticate(request['username'], request['password'])
|
50
|
+
return fail!(:invalid_credentials) if !@auth_info
|
51
|
+
|
52
|
+
@expresso_user_info = @auth_client.get_user_data
|
53
|
+
|
54
|
+
@user_info = map_user_data(@expresso_user_info)
|
55
|
+
|
56
|
+
super
|
57
|
+
rescue Exception => e
|
58
|
+
return fail!(:expressov3_error, e)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def map_user_data(expresso_user_info)
|
63
|
+
self.class.map_user(@@config, expresso_user_info)
|
64
|
+
end
|
65
|
+
|
66
|
+
uid {
|
67
|
+
@user_info["username"]
|
68
|
+
}
|
69
|
+
info {
|
70
|
+
@user_info
|
71
|
+
}
|
72
|
+
extra {
|
73
|
+
{ :raw_info => @expresso_user_info }
|
74
|
+
}
|
75
|
+
|
76
|
+
def self.map_user(mapper, object)
|
77
|
+
user = {}
|
78
|
+
mapper.each do |key, value|
|
79
|
+
case value
|
80
|
+
when String
|
81
|
+
values_keys = value.split('::')
|
82
|
+
value_key = values_keys[0]
|
83
|
+
sub_value_key = values_keys[1]
|
84
|
+
#puts "KEY: #{value_key}"
|
85
|
+
#puts "SUBKEY: #{sub_value_key}"
|
86
|
+
if object && object.has_key?(value_key) && object[value_key] && object[value_key].has_key?(sub_value_key)
|
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
|
105
|
+
end
|
106
|
+
end
|
107
|
+
user
|
108
|
+
end
|
109
|
+
|
110
|
+
protected
|
111
|
+
|
112
|
+
def missing_credentials?
|
113
|
+
request['username'].nil? or request['username'].empty? or request['password'].nil? or request['password'].empty?
|
114
|
+
end # missing_credentials?
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
OmniAuth.config.add_camelization 'expressov3', 'ExpressoV3'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/omniauth-expressov3/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.add_runtime_dependency 'omniauth', '~> 1.0'
|
5
|
+
|
6
|
+
gem.add_development_dependency 'maruku', '~> 0.6'
|
7
|
+
gem.add_development_dependency 'simplecov', '~> 0.4'
|
8
|
+
gem.add_development_dependency 'rack-test', '~> 0.5'
|
9
|
+
gem.add_development_dependency 'rake', '~> 0.8'
|
10
|
+
gem.add_development_dependency 'rspec', '~> 2.7'
|
11
|
+
|
12
|
+
gem.name = 'omniauth-expressov3'
|
13
|
+
gem.version = OmniAuth::ExpressoV3::VERSION
|
14
|
+
gem.description = %q{Internal authentication handlers for OmniAuth.}
|
15
|
+
gem.summary = gem.description
|
16
|
+
gem.email = ['abner.silva@gmail.com']
|
17
|
+
gem.homepage = 'http://github.com/abner/omniauth-expressov3'
|
18
|
+
gem.authors = ['Abner Oliveira']
|
19
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
20
|
+
gem.files = `git ls-files`.split("\n")
|
21
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
gem.require_paths = ['lib']
|
23
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if gem.respond_to? :required_rubygems_version=
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "OmniAuth::ExpressoV3::AuthClient" do
|
3
|
+
|
4
|
+
describe 'authenticate' do
|
5
|
+
it 'should authenticate' do
|
6
|
+
auth = OmniAuth::ExpressoV3::AuthClient.new
|
7
|
+
auth_data = auth.authenticate(ENV['EXPRESSO_USERNAME'], ENV['EXPRESSO_PASSWORD'])
|
8
|
+
expect(auth_data).not_to be(nil)
|
9
|
+
expect(auth_data['keys']).not_to be(nil)
|
10
|
+
data = auth.get_user_data
|
11
|
+
|
12
|
+
expect(data['currentAccount']).not_to be(nil)
|
13
|
+
expect(data['userContact']).not_to be(nil)
|
14
|
+
auth.close
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
describe "OmniAuth::Strategies::ExpressoV3" do
|
4
|
+
|
5
|
+
class ExpressoV3Provider < OmniAuth::Strategies::ExpressoV3; end
|
6
|
+
|
7
|
+
let(:app) do
|
8
|
+
Rack::Builder.new {
|
9
|
+
use OmniAuth::Test::PhonySession
|
10
|
+
use ExpressoV3Provider, :name => 'expressov3', :title => 'MyExpressoV3 Form'
|
11
|
+
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
|
12
|
+
}.to_app
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:session) do
|
16
|
+
last_request.env['rack.session']
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should add a camelization for itself' do
|
20
|
+
expect(OmniAuth::Utils.camelize('expressov3')).to eq('ExpressoV3')
|
21
|
+
end
|
22
|
+
#
|
23
|
+
describe '/auth/expressov3' do
|
24
|
+
before(:each){ get '/auth/expressov3' }
|
25
|
+
|
26
|
+
it 'should display a form' do
|
27
|
+
last_response.status.should == 200
|
28
|
+
last_response.body.should be_include("<form")
|
29
|
+
end
|
30
|
+
#
|
31
|
+
it 'should have the callback as the action for the form' do
|
32
|
+
last_response.body.should be_include("action='/auth/expressov3/callback'")
|
33
|
+
end
|
34
|
+
#
|
35
|
+
it 'should have a text field for each of the fields' do
|
36
|
+
last_response.body.scan('<input').size.should == 2
|
37
|
+
end
|
38
|
+
it 'should have a label of the form title' do
|
39
|
+
last_response.body.scan('MyExpressoV3 Form').size.should > 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'post /auth/expressov3/callback' do
|
44
|
+
before(:each) do
|
45
|
+
@auth = double(OmniAuth::ExpressoV3::AuthClient)
|
46
|
+
@auth.stub(:authenticate)
|
47
|
+
OmniAuth::ExpressoV3::AuthClient.stub(:new).and_return(@auth)
|
48
|
+
@auth_failure = {}
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'failure' do
|
52
|
+
before(:each) do
|
53
|
+
@auth.stub(:authenticate).and_return(false)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when username is not preset" do
|
57
|
+
it 'should redirect to error page' do
|
58
|
+
post('/auth/expressov3/callback', {})
|
59
|
+
|
60
|
+
expect(last_response).to be_redirect
|
61
|
+
expect(last_response.headers['Location']).to match(%r{missing_credentials})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when username is empty" do
|
66
|
+
it 'should redirect to error page' do
|
67
|
+
post('/auth/expressov3/callback', {:username => ""})
|
68
|
+
|
69
|
+
expect(last_response).to be_redirect
|
70
|
+
expect(last_response.headers['Location']).to match(%r{missing_credentials})
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when username is present" do
|
75
|
+
context "and password is not preset" do
|
76
|
+
it 'should redirect to error page' do
|
77
|
+
post('/auth/expressov3/callback', {:username => "ping"})
|
78
|
+
|
79
|
+
expect(last_response).to be_redirect
|
80
|
+
expect(last_response.headers['Location']).to match(%r{missing_credentials})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "and password is empty" do
|
85
|
+
it 'should redirect to error page' do
|
86
|
+
post('/auth/expressov3/callback', {:username => "ping", :password => ""})
|
87
|
+
|
88
|
+
expect(last_response).to be_redirect
|
89
|
+
expect(last_response.headers['Location']).to match(%r{missing_credentials})
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when username and password are present" do
|
95
|
+
context "and authenticate on Expresso server failed" do
|
96
|
+
it 'should redirect to error page' do
|
97
|
+
post('/auth/expressov3/callback', {:username => 'ping', :password => 'password'})
|
98
|
+
|
99
|
+
expect(last_response).to be_redirect
|
100
|
+
expect(last_response.headers['Location']).to match(%r{invalid_credentials})
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and communication with ExpressoV3 server caused an exception" do
|
106
|
+
before :each do
|
107
|
+
@auth.stub(:authenticate).and_throw(Exception.new('connection_error'))
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should redirect to error page' do
|
111
|
+
post('/auth/expressov3/callback', {:username => "ping", :password => "password"})
|
112
|
+
|
113
|
+
expect(last_response).to be_redirect
|
114
|
+
expect(last_response.headers['Location']).to match(%r{expressov3_error})
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
context 'success' do
|
121
|
+
let(:auth_hash){ last_request.env['omniauth.auth'] }
|
122
|
+
|
123
|
+
let(:hash_result) {
|
124
|
+
json_path = File.expand_path(File.dirname(__FILE__) + '../../../result.json')
|
125
|
+
File.open(json_path) do |f|
|
126
|
+
json = f.read
|
127
|
+
return JSON.parse(json)
|
128
|
+
end
|
129
|
+
}
|
130
|
+
|
131
|
+
before(:each) do
|
132
|
+
@auth = double(OmniAuth::ExpressoV3::AuthClient)
|
133
|
+
@auth.stub(:authenticate).and_return({})
|
134
|
+
@auth.stub(:get_user_data).and_return({})
|
135
|
+
OmniAuth::ExpressoV3::AuthClient.stub(:new).and_return(@auth)
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should not redirect to error page' do
|
140
|
+
post('/auth/expressov3/callback', {:username => 'ping', :password => 'password'})
|
141
|
+
expect(last_response).not_to be_redirect
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should map user info to Auth Hash' do
|
145
|
+
@auth.stub(:get_user_data).and_return(hash_result)
|
146
|
+
post('/auth/expressov3/callback', {:username => 'ping', :password => 'password'})
|
147
|
+
expect(auth_hash.provider).to eq('expressov3')
|
148
|
+
expect(auth_hash.info.account_id).to eq('111111111')
|
149
|
+
expect(auth_hash.info.username).to eq('11111111111')
|
150
|
+
expect(auth_hash.info.email).to eq('joao.ninguem@serpro.gov.br')
|
151
|
+
expect(auth_hash.info.first_name).to eq('Joao')
|
152
|
+
expect(auth_hash.info.last_name).to eq('Ninguem')
|
153
|
+
expect(auth_hash.info.name).to eq('Joao Ninguem')
|
154
|
+
expect(auth_hash.info.telephone).to eq('(71)1111-1111')
|
155
|
+
expect(auth_hash.info.organization_unit).to eq('SUPDE/DESDR/DE5CT')
|
156
|
+
expect(auth_hash.info.tine_key).to eq('tine_key')
|
157
|
+
expect(auth_hash.info.json_key).to eq('json_key')
|
158
|
+
expect(auth_hash.info.contact_id).to eq('contact_id')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
data/spec/result.json
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
{
|
2
|
+
"keys": {
|
3
|
+
"tine_key": "tine_key",
|
4
|
+
"json_key": "json_key"
|
5
|
+
},
|
6
|
+
"currentAccount": {
|
7
|
+
"accountId": "111111111",
|
8
|
+
"accountLoginName": "11111111111",
|
9
|
+
"accountLastLogin": "2015-02-10 13:42:15",
|
10
|
+
"accountLastLoginfrom": "161.148.31.232",
|
11
|
+
"accountLastPasswordChange": "2015-01-05 11:48:58",
|
12
|
+
"accountStatus": "enabled",
|
13
|
+
"accountExpires": null,
|
14
|
+
"accountPrimaryGroup": "888",
|
15
|
+
"accountHomeDirectory": "/home/11111111111",
|
16
|
+
"accountLoginShell": "/bin/bash",
|
17
|
+
"accountDisplayName": "Joao Ninguem",
|
18
|
+
"accountFullName": "Joao Ninguem",
|
19
|
+
"accountFirstName": "Joao",
|
20
|
+
"accountLastName": "Ninguem",
|
21
|
+
"accountEmailAddress": "joao.ninguem@serpro.gov.br",
|
22
|
+
"lastLoginFailure": "2014-06-13 11:59:25",
|
23
|
+
"loginFailures": 0,
|
24
|
+
"contact_id": "contact_id",
|
25
|
+
"openid": null,
|
26
|
+
"visibility": "displayed",
|
27
|
+
"container_id": 1,
|
28
|
+
"imapUser": {
|
29
|
+
"emailMailQuota": 500,
|
30
|
+
"emailMailSize": 435,
|
31
|
+
"emailUserId": "11111111111",
|
32
|
+
"emailForwardOnly": 0,
|
33
|
+
"emailUsername": "11111111111"
|
34
|
+
},
|
35
|
+
"emailUser": {
|
36
|
+
"emailForwards": [],
|
37
|
+
"emailForwardOnly": false,
|
38
|
+
"emailAliases": [
|
39
|
+
"joao.ninguem@mail.serpro.gov.br"
|
40
|
+
],
|
41
|
+
"emailAddress": "joao.ninguem@serpro.gov.br"
|
42
|
+
},
|
43
|
+
"accountPasswordExpired": "no",
|
44
|
+
"accountDN": "ou=reg,ou=regsdr,dc=serpro,dc=gov,dc=br",
|
45
|
+
"smtpUser": {
|
46
|
+
"emailForwards": [],
|
47
|
+
"emailForwardOnly": false,
|
48
|
+
"emailAliases": [
|
49
|
+
"joao.ninguem@mail.serpro.gov.br"
|
50
|
+
],
|
51
|
+
"emailAddress": "joao.ninguem@serpro.gov.br"
|
52
|
+
}
|
53
|
+
},
|
54
|
+
"userContact": {
|
55
|
+
"id": "contact_id",
|
56
|
+
"adr_one_countryname": "",
|
57
|
+
"adr_one_locality": null,
|
58
|
+
"adr_one_postalcode": null,
|
59
|
+
"adr_one_region": null,
|
60
|
+
"adr_one_street": null,
|
61
|
+
"adr_one_street2": null,
|
62
|
+
"adr_one_lon": null,
|
63
|
+
"adr_one_lat": null,
|
64
|
+
"adr_two_countryname": "",
|
65
|
+
"adr_two_locality": null,
|
66
|
+
"adr_two_postalcode": null,
|
67
|
+
"adr_two_region": null,
|
68
|
+
"adr_two_street": null,
|
69
|
+
"adr_two_street2": null,
|
70
|
+
"adr_two_lon": null,
|
71
|
+
"adr_two_lat": null,
|
72
|
+
"assistent": null,
|
73
|
+
"bday": null,
|
74
|
+
"calendar_uri": null,
|
75
|
+
"email": "joao.ninguem@serpro.gov.br",
|
76
|
+
"email_home": "",
|
77
|
+
"freebusy_uri": null,
|
78
|
+
"geo": null,
|
79
|
+
"note": null,
|
80
|
+
"container_id": 1,
|
81
|
+
"pubkey": null,
|
82
|
+
"role": null,
|
83
|
+
"room": null,
|
84
|
+
"salutation": null,
|
85
|
+
"title": null,
|
86
|
+
"tz": null,
|
87
|
+
"url": "",
|
88
|
+
"url_home": "",
|
89
|
+
"n_fn": "Joao Ninguem",
|
90
|
+
"n_fileas": "Joao Ninguem",
|
91
|
+
"n_family": "Ninguem",
|
92
|
+
"n_given": "Joao",
|
93
|
+
"n_middle": null,
|
94
|
+
"n_prefix": null,
|
95
|
+
"n_suffix": null,
|
96
|
+
"org_name": null,
|
97
|
+
"org_unit": "SUPDE/DESDR/DE5CT",
|
98
|
+
"tel_assistent": null,
|
99
|
+
"tel_car": null,
|
100
|
+
"tel_cell": "(71)1111-1111",
|
101
|
+
"tel_cell_private": null,
|
102
|
+
"tel_fax": null,
|
103
|
+
"tel_fax_home": null,
|
104
|
+
"tel_home": null,
|
105
|
+
"tel_other": null,
|
106
|
+
"tel_pager": null,
|
107
|
+
"tel_prefer": null,
|
108
|
+
"tel_work": "(71)1111-1111",
|
109
|
+
"created_by": null,
|
110
|
+
"creation_time": "2013-07-16 21:36:04",
|
111
|
+
"last_modified_by": null,
|
112
|
+
"last_modified_time": null,
|
113
|
+
"is_deleted": "0",
|
114
|
+
"deleted_by": null,
|
115
|
+
"deleted_time": null,
|
116
|
+
"seq": 0,
|
117
|
+
"type": "user",
|
118
|
+
"jpegphoto": 1,
|
119
|
+
"account_id": "111111111"
|
120
|
+
}
|
121
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
$:.unshift File.expand_path('..', __FILE__)
|
5
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
6
|
+
require 'simplecov'
|
7
|
+
SimpleCov.start
|
8
|
+
require 'rspec'
|
9
|
+
require 'rack/test'
|
10
|
+
require 'omniauth'
|
11
|
+
require 'omniauth-expressov3'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include Rack::Test::Methods
|
15
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
16
|
+
|
17
|
+
OmniAuth.config.logger = Logger.new(File.expand_path('../omniauth.log', __FILE__))
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-expressov3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abner Oliveira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-10 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: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: maruku
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.7'
|
97
|
+
description: Internal authentication handlers for OmniAuth.
|
98
|
+
email:
|
99
|
+
- abner.silva@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- CONTRIBUTING.md
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- lib/omniauth-expressov3.rb
|
111
|
+
- lib/omniauth-expressov3/expressov3_auth_client.rb
|
112
|
+
- lib/omniauth-expressov3/jsonrpc_tine_connection.rb
|
113
|
+
- lib/omniauth-expressov3/version.rb
|
114
|
+
- lib/omniauth/strategies/expressov3.rb
|
115
|
+
- omniauth-expressov3.gemspec
|
116
|
+
- spec/omniauth-expressov3/expressov3_auth_client_2_spec.rb
|
117
|
+
- spec/omniauth/strategies/expressov3_spec.rb
|
118
|
+
- spec/result.json
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
homepage: http://github.com/abner/omniauth-expressov3
|
121
|
+
licenses: []
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.3.6
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Internal authentication handlers for OmniAuth.
|
143
|
+
test_files: []
|