ehsso 0.1.0 → 0.1.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 +4 -4
- data/README.md +7 -2
- data/app/models/person.rb +86 -0
- data/ehsso.gemspec +2 -2
- data/lib/ehsso/configuration.rb +5 -5
- data/lib/ehsso/engine.rb +1 -2
- data/lib/ehsso/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16742fa33f79490044c2ab677c3f20956458577a
|
4
|
+
data.tar.gz: a91ffe95f7a5c167b751fdbeea1ec01393e93713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e677c3b519529f3af47800e19b07fb1a4b9a46d4a5341eb3a8618d646f2db5f329e2bfec1c855d249729b821455cd40976bc37dbca4f6ec92f27cefce5af98b5
|
7
|
+
data.tar.gz: 567fc4952153ac81af3ba67f368fcda477ea4d3f9722fdc3af0f3aad3884468df7114f4bcf2b1bdc99b1c6dafe806c31483b4eadba80be7e666359aa3aa2ae5a
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[](https://badge.fury.io/rb/ehsso)
|
2
|
+
[](https://codeclimate.com/github/thomis/ehsso)
|
3
|
+
[](https://gemnasium.com/github.com/thomis/ehsso)
|
4
|
+
|
1
5
|
# ehsso
|
2
6
|
|
3
7
|
Company specific Single Sign On for Rails applications.
|
@@ -20,7 +24,8 @@ Ehsso.configure do |config|
|
|
20
24
|
config.module_key = 'my_module_key'
|
21
25
|
|
22
26
|
# Service Endpoint
|
23
|
-
config.
|
27
|
+
config.base_url = 'http://{host}:{port}'
|
28
|
+
config.username_and_password = 'username:password'
|
24
29
|
end
|
25
30
|
```
|
26
31
|
|
@@ -30,4 +35,4 @@ to do....
|
|
30
35
|
|
31
36
|
## Contributing
|
32
37
|
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/thomis/ehsso.
|
data/app/models/person.rb
CHANGED
@@ -8,12 +8,19 @@ module Ehsso
|
|
8
8
|
attr_accessor :last_name
|
9
9
|
attr_accessor :email
|
10
10
|
|
11
|
+
attr_reader :last_error_message
|
12
|
+
|
11
13
|
def initialize(args={})
|
12
14
|
@id = args[:id]
|
13
15
|
@reference = args[:reference]
|
14
16
|
@first_name = args[:first_name]
|
15
17
|
@last_name = args[:last_name]
|
16
18
|
@email = args[:email]
|
19
|
+
|
20
|
+
# for this purpose we deal with only one module
|
21
|
+
@module_key = nil
|
22
|
+
@module_name = nil
|
23
|
+
@roles = []
|
17
24
|
end
|
18
25
|
|
19
26
|
# def method_missing(method)
|
@@ -30,11 +37,90 @@ module Ehsso
|
|
30
37
|
|
31
38
|
person = Ehsso::Person.new()
|
32
39
|
|
40
|
+
# reference (mandatory)
|
41
|
+
return nil if header['HTTP_NIBR521'].nil? || header['HTTP_NIBR521'].size == 0
|
42
|
+
person.reference = header['HTTP_NIBR521'].downcase
|
43
|
+
|
44
|
+
# first name
|
45
|
+
person.first_name = header['HTTP_NIBRFIRST'] if header['HTTP_NIBRFIRST'] && header['HTTP_NIBRFIRST'].strip.size > 0
|
46
|
+
|
47
|
+
# last name
|
48
|
+
person.last_name = header['HTTP_NIBRLAST'] if header["HTTP_NIBRLAST"] && header['HTTP_NIBRFIRST'].strip.size > 0
|
49
|
+
|
50
|
+
# email
|
51
|
+
person.email = header['HTTP_NIBREMAIL'].downcase if header['HTTP_NIBREMAIL'] && header['HTTP_NIBREMAIL'].strip.size > 0
|
33
52
|
|
34
53
|
return person
|
35
54
|
end
|
36
55
|
|
56
|
+
def fetch
|
57
|
+
url = [Ehsso.configuration.base_url, 'people'].join('/')
|
58
|
+
userpwd = Ehsso.configuration.username_and_password
|
59
|
+
response = Typhoeus.post(url, body: payload(action: 'people.modules.roles'), userpwd: userpwd)
|
60
|
+
handle_response(response)
|
61
|
+
end
|
62
|
+
|
37
63
|
|
64
|
+
def fetch_or_create
|
65
|
+
url = [Ehsso.configuration.base_url, 'people'].join('/')
|
66
|
+
userpwd = Ehsso.configuration.username_and_password
|
67
|
+
response = Typhoeus.post(url, body: payload(action: 'people_with_guest_registration_if_missing.modules.roles'), userpwd: userpwd)
|
68
|
+
handle_response(response)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def payload(args={})
|
74
|
+
{
|
75
|
+
type: 'request',
|
76
|
+
action: args[:action] || 'people.modules.roles',
|
77
|
+
request: [
|
78
|
+
{
|
79
|
+
reference: self.reference,
|
80
|
+
first_name: self.first_name,
|
81
|
+
last_name: self.last_name,
|
82
|
+
email: self.email,
|
83
|
+
modules: [
|
84
|
+
{
|
85
|
+
reference: args[:module_key] || Ehsso.configuration.module_key
|
86
|
+
}
|
87
|
+
]
|
88
|
+
}
|
89
|
+
]
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def handle_response(response)
|
94
|
+
if response.code == 200
|
95
|
+
begin
|
96
|
+
data = JSON.parse(response.body)
|
97
|
+
|
98
|
+
item = data['response'][0]
|
99
|
+
self.id = item['id']
|
100
|
+
self.reference = item['reference']
|
101
|
+
self.first_name = item['first_name']
|
102
|
+
self.last_name = item['last_name']
|
103
|
+
self.email = item['email']
|
104
|
+
|
105
|
+
modul = item['modules'][0]
|
106
|
+
self.module_key = modul['reference']
|
107
|
+
self.module_name = modul['name']
|
108
|
+
self.roles = modul['roles']
|
109
|
+
self.last_error_message = nil
|
110
|
+
rescue
|
111
|
+
self.last_error_message = "Unable to parse servcie response data"
|
112
|
+
end
|
113
|
+
else
|
114
|
+
# something went wrong
|
115
|
+
begin
|
116
|
+
# try to parse the body to get valid error message
|
117
|
+
data = JSON.parse(response.body)
|
118
|
+
self.last_error_message = data['response_message']
|
119
|
+
rescue
|
120
|
+
self.last_error_message = "#{response.request.url}: [#{response.code}] #{response.return_message}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
38
124
|
|
39
125
|
end
|
40
126
|
|
data/ehsso.gemspec
CHANGED
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.14"
|
26
|
-
spec.add_development_dependency "rake", "~>
|
26
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
28
|
spec.add_development_dependency "rails", "~> 5.1"
|
29
29
|
|
30
|
-
spec.add_runtime_dependency("
|
30
|
+
spec.add_runtime_dependency("typhoeus", "~> 1.1.2")
|
31
31
|
end
|
data/lib/ehsso/configuration.rb
CHANGED
@@ -2,13 +2,13 @@ module Ehsso
|
|
2
2
|
|
3
3
|
class Configuration
|
4
4
|
attr_accessor :module_key
|
5
|
-
attr_accessor :
|
6
|
-
attr_accessor :
|
5
|
+
attr_accessor :base_url
|
6
|
+
attr_accessor :username_and_password
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
9
|
+
@module_key = ''
|
10
|
+
@base_url = ''
|
11
|
+
@username_and_password = nil
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
data/lib/ehsso/engine.rb
CHANGED
data/lib/ehsso/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehsso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Steiner
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: typhoeus
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.1.2
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.1.2
|
83
83
|
description: EH Single Sign On
|
84
84
|
email:
|
85
85
|
- thomas.steiner@ikey.ch
|