wm_okta_helper 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -9
- data/lib/wm_okta_helper/get_user_groups.rb +61 -0
- data/lib/wm_okta_helper/version.rb +1 -1
- data/lib/wm_okta_helper.rb +4 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b12e20bcfd16dc8c7a615a7afab48102145d010
|
4
|
+
data.tar.gz: 58243c8ba5aa45206188924f29ace72c66303848
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d75bac711ae068b6d0677cd2e1ac774e59ceddb69bcbbc75684431d4d10ba359ba67148a0419f515214065701fabab50b7a9bc6719a235804c64ad845fd21130
|
7
|
+
data.tar.gz: ebd161332ba932fe52393e35935a7eb048559098037f70fa7b1f163d0748afae72cdca50c275e5770cd3e933533c782c5eb7ba0b2d36cb9ef2a858121ef6091d
|
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.4)
|
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.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.
|
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.6.0)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
json (2.1.0)
|
32
|
-
json-jwt (1.
|
33
|
-
activesupport
|
32
|
+
json-jwt (1.10.2)
|
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
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.
|
105
|
+
1.16.6
|
@@ -0,0 +1,61 @@
|
|
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.includes('otto_')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_data
|
47
|
+
uri = URI.parse(site)
|
48
|
+
request = Net::HTTP::Get.new(request_url)
|
49
|
+
request.content_type = 'application/json'
|
50
|
+
request['Accept'] = 'application/json'
|
51
|
+
request['Authorization'] = "SSWS #{@api_key}"
|
52
|
+
|
53
|
+
req_options = { use_ssl: uri.scheme == 'https' }
|
54
|
+
|
55
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
56
|
+
http.request(request)
|
57
|
+
end
|
58
|
+
response.body.present? ? JSON.parse(response.body) : []
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
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
|
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.4
|
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-09-11 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
|