checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA1:
3
- metadata.gz: 2b9cfe662559d4e78d403bede3aa3fe5cfe7c515
4
- data.tar.gz: af98b948dee82394a317c009a2345a411485fce4
3
+ metadata.gz: 8c7aa02f11102390e977513389af9287dace7440
4
+ data.tar.gz: 1fde83ec917ff1311a2a6b863380831e0fa47e9e
5
5
SHA512:
6
- metadata.gz: 792a3c1c5859930df3e94a753899ef8c4fa6929f650a276b05bc1cebb3732e372ea053570c07eb6ac279197f739410bb8c3f774ce33c9d7084054a4995354e30
7
- data.tar.gz: b4ab45f38e91db2196712beca94f95a3c41b129db305b6cb14779b2cb0c13cf208add8de683c248c9dc60d796165e4cdeb914e7a48c4af903c49f0f58fd4fd3e
6
+ metadata.gz: 5cc00508aac733cda66f624d811e690214910b88e085c77038abb98486369b5511bf5b5127b3a0d64ef9145c8750cc77b09f8446e32c24a794d3d659688de9ce
7
+ data.tar.gz: eadd03a83b10e6c64efe506c2d15a8925bd2543abf53042fd831de2df76aa8803def3e1a66675a6fce470073e4ada2ccd095c3783e9ac8566eb0e39a4af6f1ba
data/.circleci/config.yml CHANGED
@@ -9,7 +9,6 @@ jobs:
9
9
10
10
steps:
11
11
- checkout
12
-
13
12
# Download and cache dependencies
14
13
- restore_cache:
15
14
keys:
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.5)
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,65 @@
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 cache_key
33
+ "user-groups-#{@user}"
34
+ end
35
+
36
+ def okta_groups
37
+ Rails.cache.fetch(cache_key, expires_in: 1.hour) do
38
+ groups = []
39
+ fetch_data.each do |g|
40
+ group_name = g.dig('profile', 'name')
41
+ groups << group_name if group_name.include?('otto_')
42
+ end
43
+ groups
44
+ end
45
+ end
46
+
47
+ def fetch_data
48
+ uri = URI.parse(site)
49
+ req_options = { use_ssl: uri.scheme == 'https' }
50
+
51
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
52
+ http.request(request)
53
+ end
54
+ response.body.present? ? JSON.parse(response.body) : []
55
+ end
56
+
57
+ def request
58
+ @request ||= Net::HTTP::Get.new(request_url)
59
+ @request.content_type = 'application/json'
60
+ @request['Accept'] = 'application/json'
61
+ @request['Authorization'] = "SSWS #{@api_key}"
62
+ @request
63
+ end
64
+ end
65
+ end
data/lib/wm_okta_helper/validate_session.rb CHANGED
@@ -3,7 +3,7 @@
3
3
module WmOktaHelper
4
4
class ValidateSession
5
5
def initialize(options)
6
- @session_token = options[:sessionToken]
6
+ @request_object = options[:request]
7
7
@okta_org = options[:okta_org]
8
8
@okta_domain = options[:okta_domain]
9
9
end
@@ -14,10 +14,13 @@ 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
- attr_accessor :session_token, :okta_org, :okta_domain
23
+ attr_accessor :request_object, :okta_org, :okta_domain
21
24
22
25
private
23
26
@@ -26,7 +29,7 @@ module WmOktaHelper
26
29
end
27
30
28
31
def request_body
29
- { sessionToken: session_token }
32
+ { sessionToken: request_object.headers['Authorization'] }
30
33
end
31
34
end
32
35
end
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.0'
4
+ VERSION = '0.2.5'
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.0
4
+ version: 0.2.5
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-20 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