wm_okta_helper 0.2.2 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -11
- data/lib/wm_okta_helper.rb +4 -2
- data/lib/wm_okta_helper/authenticate_api_request.rb +1 -1
- data/lib/wm_okta_helper/create_session.rb +26 -9
- data/lib/wm_okta_helper/get_user_groups.rb +59 -0
- data/lib/wm_okta_helper/version.rb +1 -1
- data/wm_okta_helper.gemspec +2 -1
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6d055c45a27a8b7131abc256cf626a86e66a670
|
4
|
+
data.tar.gz: b48c2fbf0b4bdec9ea86930689ddbe555be21665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e8a99048148d581bda980124f587c61095beeff1529f4ccc610a5abaa4c9ac9b3e11380745a6d9f4bce12c3f051c4f7286d910657be4ed56d7c5183b3df79c0
|
7
|
+
data.tar.gz: d21e379d09df50cedec9b350728bc1227a7f25e377d9ae069b9652d4fc7e72d2b0965615e2f0f532779806064bfc58fea81cc131095cfa07782b056e3b046de6
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wm_okta_helper (0.2.
|
4
|
+
wm_okta_helper (0.2.7)
|
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.
|
11
|
+
activesupport (5.2.4)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
@@ -17,25 +17,25 @@ 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.
|
20
|
+
bindata (2.4.4)
|
21
21
|
byebug (10.0.2)
|
22
22
|
coderay (1.1.2)
|
23
|
-
concurrent-ruby (1.
|
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.
|
29
|
+
i18n (1.7.0)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
json (2.1.0)
|
32
|
-
json-jwt (1.
|
33
|
-
activesupport
|
32
|
+
json-jwt (1.11.0)
|
33
|
+
activesupport (>= 4.2)
|
34
34
|
aes_key_wrap
|
35
35
|
bindata
|
36
|
-
jwt (2.1
|
36
|
+
jwt (2.2.1)
|
37
37
|
method_source (0.9.0)
|
38
|
-
minitest (5.
|
38
|
+
minitest (5.13.0)
|
39
39
|
parallel (1.12.1)
|
40
40
|
parser (2.5.1.2)
|
41
41
|
ast (~> 2.4.0)
|
@@ -79,6 +79,7 @@ GEM
|
|
79
79
|
simplecov-html (~> 0.10.0)
|
80
80
|
simplecov-html (0.10.2)
|
81
81
|
thread_safe (0.3.6)
|
82
|
+
timecop (0.9.1)
|
82
83
|
tzinfo (1.2.5)
|
83
84
|
thread_safe (~> 0.1)
|
84
85
|
unicode-display_width (1.4.0)
|
@@ -91,15 +92,16 @@ PLATFORMS
|
|
91
92
|
ruby
|
92
93
|
|
93
94
|
DEPENDENCIES
|
94
|
-
bundler (~> 1.16)
|
95
|
+
bundler (~> 1.16.6)
|
95
96
|
pry-byebug
|
96
97
|
rake (~> 10.0)
|
97
98
|
rspec (~> 3.0)
|
98
99
|
rspec_junit_formatter
|
99
100
|
rubocop (~> 0.54.0)
|
100
101
|
simplecov
|
102
|
+
timecop
|
101
103
|
webmock
|
102
104
|
wm_okta_helper!
|
103
105
|
|
104
106
|
BUNDLED WITH
|
105
|
-
|
107
|
+
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 :
|
11
|
-
'wm_okta_helper/
|
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
|
@@ -3,25 +3,35 @@
|
|
3
3
|
module WmOktaHelper
|
4
4
|
class CreateSession
|
5
5
|
def initialize(options)
|
6
|
-
@
|
7
|
-
@password = options[:password]
|
8
|
-
@okta_org = options[:okta_org]
|
9
|
-
@okta_domain = options[:okta_domain]
|
6
|
+
@options = options
|
10
7
|
end
|
11
8
|
|
12
9
|
def call
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
).call
|
10
|
+
check_options
|
11
|
+
raise 'Not authorized' if response['sessionToken'].blank?
|
12
|
+
response
|
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
|
@@ -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/wm_okta_helper.gemspec
CHANGED
@@ -36,12 +36,13 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.add_dependency 'json-jwt'
|
37
37
|
spec.add_dependency 'jwt'
|
38
38
|
|
39
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
39
|
+
spec.add_development_dependency 'bundler', '~> 1.16.6'
|
40
40
|
spec.add_development_dependency 'pry-byebug'
|
41
41
|
spec.add_development_dependency 'rake', '~> 10.0'
|
42
42
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
43
43
|
spec.add_development_dependency 'rspec_junit_formatter'
|
44
44
|
spec.add_development_dependency 'rubocop', '~> 0.54.0'
|
45
45
|
spec.add_development_dependency 'simplecov'
|
46
|
+
spec.add_development_dependency 'timecop'
|
46
47
|
spec.add_development_dependency 'webmock'
|
47
48
|
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.
|
4
|
+
version: 0.2.7
|
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:
|
11
|
+
date: 2019-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-jwt
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.16.6
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.16.6
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry-byebug
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: timecop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: webmock
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,6 +188,7 @@ files:
|
|
174
188
|
- lib/wm_okta_helper.rb
|
175
189
|
- lib/wm_okta_helper/authenticate_api_request.rb
|
176
190
|
- lib/wm_okta_helper/create_session.rb
|
191
|
+
- lib/wm_okta_helper/get_user_groups.rb
|
177
192
|
- lib/wm_okta_helper/post_request.rb
|
178
193
|
- lib/wm_okta_helper/validate_session.rb
|
179
194
|
- lib/wm_okta_helper/version.rb
|
@@ -199,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
214
|
version: '0'
|
200
215
|
requirements: []
|
201
216
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.6.14
|
217
|
+
rubygems_version: 2.6.14.1
|
203
218
|
signing_key:
|
204
219
|
specification_version: 4
|
205
220
|
summary: Helper library for validating Okta jwt token.
|