checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA1:
3
- metadata.gz: bebe37d71abfe29190877dfde7376974fa3efe33
4
- data.tar.gz: 238ffd793c5ef19b749572ddebbfb5d1db4a00b3
3
+ metadata.gz: 65af61e943a8915d7cfc8c459e2d5d43a5c9da95
4
+ data.tar.gz: fe8760d47e69f3d567c09c57878dd2484f84be7a
5
5
SHA512:
6
- metadata.gz: 110f0e2fb402273f037380f2f1ad717c0b4807df9ad726a602037f90c0a82b090958a458582fe046214ce74c254cf4971101b651969783fb2ee97e3bafa056e0
7
- data.tar.gz: 3a6b77bc20077265d7fc500506f52b891f2375ce3a3dbe80684b20f12ec1f1aa9c393de9f545fdb0e344d5015f0e46ed84961557c24079585e01a4fbfd142f3e
6
+ metadata.gz: a983c3d1d896383d8188ba4401cf5370e5a3db3ef7cb9d846829ad2027d4a754ed5ebaf0bbaf762597416ca95a80ffa1e399df88cd2eab79731c8291fe14e3ce
7
+ data.tar.gz: ffc344f5904b4d6b9a169bf4f2a65ca5798670c6b71724e2b180626eb939c0217e44924b1b7371a262df77bd1159fd8e9dad173d21746ec9baf3fe39e19632db
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
PATH
2
2
remote: .
3
3
specs:
4
- wm_okta_helper (0.2.0)
4
+ wm_okta_helper (0.2.6)
5
5
json-jwt
6
6
jwt
7
7
8
8
GEM
9
9
remote: https://rubygems.org/
10
10
specs:
11
- activesupport (5.2.0)
11
+ activesupport (5.2.3)
12
12
concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
i18n (>= 0.7, < 2)
14
14
minitest (~> 5.1)
@@ -17,23 +17,23 @@ GEM
17
17
public_suffix (>= 2.0.2, < 4.0)
18
18
aes_key_wrap (1.0.1)
19
19
ast (2.4.0)
20
- bindata (2.4.3)
20
+ bindata (2.4.4)
21
21
byebug (10.0.2)
22
22
coderay (1.1.2)
23
- concurrent-ruby (1.0.5)
23
+ concurrent-ruby (1.1.5)
24
24
crack (0.4.3)
25
25
safe_yaml (~> 1.0.0)
26
26
diff-lcs (1.3)
27
27
docile (1.3.1)
28
28
hashdiff (0.3.7)
29
- i18n (1.0.1)
29
+ i18n (1.6.0)
30
30
concurrent-ruby (~> 1.0)
31
31
json (2.1.0)
32
- json-jwt (1.9.4)
33
- activesupport
32
+ json-jwt (1.10.2)
33
+ activesupport (>= 4.2)
34
34
aes_key_wrap
35
35
bindata
36
- jwt (2.1.0)
36
+ jwt (2.2.1)
37
37
method_source (0.9.0)
38
38
minitest (5.11.3)
39
39
parallel (1.12.1)
@@ -102,4 +102,4 @@ DEPENDENCIES
102
102
wm_okta_helper!
103
103
104
104
BUNDLED WITH
105
- 1.16.2
105
+ 1.16.6
data/lib/wm_okta_helper.rb CHANGED
@@ -7,8 +7,10 @@ module WmOktaHelper
7
7
'wm_okta_helper/authenticate_api_request.rb'
8
8
autoload :CreateSession,
9
9
'wm_okta_helper/create_session.rb'
10
- autoload :ValidateSession,
11
- 'wm_okta_helper/validate_session.rb'
10
+ autoload :GetUserGroups,
11
+ 'wm_okta_helper/get_user_groups.rb'
12
12
autoload :PostRequest,
13
13
'wm_okta_helper/post_request.rb'
14
+ autoload :ValidateSession,
15
+ 'wm_okta_helper/validate_session.rb'
14
16
end
data/lib/wm_okta_helper/create_session.rb CHANGED
@@ -3,25 +3,35 @@
3
3
module WmOktaHelper
4
4
class CreateSession
5
5
def initialize(options)
6
- @username = options[:username]
6
+ @options = options
7
- @password = options[:password]
8
- @okta_org = options[:okta_org]
9
- @okta_domain = options[:okta_domain]
10
7
end
11
8
12
9
def call
13
- PostRequest.new(
14
- url: url,
15
- request_body: request_body
10
+ check_options
11
+ raise 'Not authorized' if response['sessionToken'].blank?
12
+ response
16
- ).call
17
13
end
18
14
19
15
attr_accessor :username, :password, :okta_org, :okta_domain
20
16
21
17
private
22
18
19
+ def available_options
20
+ %i[username password okta_org okta_domain]
21
+ end
22
+
23
+ def check_options
24
+ missing_options = available_options.select { |o| @options[o].blank? }
25
+ if missing_options.present?
26
+ raise "Missing configuration variable: #{missing_options}"
27
+ end
28
+ available_options.each do |o|
29
+ instance_variable_set("@#{o}", @options[o])
30
+ end
31
+ end
32
+
23
33
def url
24
- "https://#{okta_org}.#{okta_domain}.com/api/v1/authn"
34
+ "https://#{@okta_org}.#{@okta_domain}.com/api/v1/authn"
25
35
end
26
36
27
37
def request_body
@@ -34,5 +44,12 @@ module WmOktaHelper
34
44
}
35
45
}
36
46
end
47
+
48
+ def response
49
+ @response ||= PostRequest.new(
50
+ url: url,
51
+ request_body: request_body
52
+ ).call
53
+ end
37
54
end
38
55
end
data/lib/wm_okta_helper/get_user_groups.rb ADDED
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module WmOktaHelper
6
+ class GetUserGroups
7
+ def initialize(options)
8
+ @user = options[:user]
9
+ @okta_org = options[:okta_org]
10
+ @okta_domain = options[:okta_domain]
11
+ @api_key = options[:api_key]
12
+ end
13
+
14
+ def call
15
+ okta_groups
16
+ end
17
+
18
+ private
19
+
20
+ def site
21
+ "https://#{@okta_org}.#{@okta_domain}.com"
22
+ end
23
+
24
+ def endpoint
25
+ "api/v1/users/#{@user}/groups"
26
+ end
27
+
28
+ def request_url
29
+ URI("#{site}/#{endpoint}")
30
+ end
31
+
32
+ def okta_groups
33
+ groups = []
34
+ fetch_data.each do |g|
35
+ group_name = g.dig('profile', 'name')
36
+ groups << group_name if group_name.include?('otto_')
37
+ end
38
+ groups
39
+ end
40
+
41
+ def fetch_data
42
+ uri = URI.parse(site)
43
+ req_options = { use_ssl: uri.scheme == 'https' }
44
+
45
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
46
+ http.request(request)
47
+ end
48
+ response.body.present? ? JSON.parse(response.body) : []
49
+ end
50
+
51
+ def request
52
+ @request ||= Net::HTTP::Get.new(request_url)
53
+ @request.content_type = 'application/json'
54
+ @request['Accept'] = 'application/json'
55
+ @request['Authorization'] = "SSWS #{@api_key}"
56
+ @request
57
+ end
58
+ end
59
+ end
data/lib/wm_okta_helper/validate_session.rb CHANGED
@@ -14,7 +14,10 @@ module WmOktaHelper
14
14
request_body: request_body
15
15
).call
16
16
17
- token['userId'].present?
17
+ return {
18
+ user_id: token['userId'],
19
+ name: token['_links']['user']['name']
20
+ } if token['userId'].present?
18
21
end
19
22
20
23
attr_accessor :request_object, :okta_org, :okta_domain
data/lib/wm_okta_helper/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
# frozen_string_literal: true
2
2
3
3
module WmOktaHelper
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.6'
5
5
end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
--- !ruby/object:Gem::Specification
2
2
name: wm_okta_helper
3
3
version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.6
5
5
platform: ruby
6
6
authors:
7
7
- Jose C Fernandez
8
8
autorequire:
9
9
bindir: exe
10
10
cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2019-09-12 00:00:00.000000000 Z
12
12
dependencies:
13
13
- !ruby/object:Gem::Dependency
14
14
name: json-jwt
@@ -174,6 +174,7 @@ files:
174
174
- lib/wm_okta_helper.rb
175
175
- lib/wm_okta_helper/authenticate_api_request.rb
176
176
- lib/wm_okta_helper/create_session.rb
177
+ - lib/wm_okta_helper/get_user_groups.rb
177
178
- lib/wm_okta_helper/post_request.rb
178
179
- lib/wm_okta_helper/validate_session.rb
179
180
- lib/wm_okta_helper/version.rb