mn_utils_gem 1.14.1 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mn_utils_gem/sso.rb +33 -12
- data/lib/mn_utils_gem/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e7292a8e70611c5bf7971d203841260cc3b2d7a84f87f249a82c0caac84175a
|
4
|
+
data.tar.gz: f6de5171379b867c8f1d002e61a1eb4d4c705437dcdd179c8d98c5e8b9485f82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e04c99269319b133fdd37462a02933123097b111f8543ad0d9a2184d209512cc8382e80f93b2e879501816fbd37e366751817be73e13803954a20b62b83122a4
|
7
|
+
data.tar.gz: bb1619401461f39a203bb075a481117dc137fe98c5430a72c8a0d19aa309715c190680f8fd381d9086532da4680af4e7df5803fb381061e7954c9edc20aebfe8
|
data/lib/mn_utils_gem/sso.rb
CHANGED
@@ -14,6 +14,10 @@ module MnUtilsAuth
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_sso_user_id(cookies)
|
17
|
+
raise ArgumentError, "ENV['MN_REDIS_URL'] is required" \
|
18
|
+
unless ENV.key? 'MN_REDIS_URL'
|
19
|
+
raise ArgumentError, "ENV['COOKIE_DOMAIN'] is required" \
|
20
|
+
unless ENV.key? 'COOKIE_DOMAIN'
|
17
21
|
parsed = get_sso cookies
|
18
22
|
return nil if parsed.nil?
|
19
23
|
parsed[:user_id]
|
@@ -23,9 +27,13 @@ module MnUtilsAuth
|
|
23
27
|
end
|
24
28
|
|
25
29
|
def get_sso(cookies)
|
30
|
+
raise ArgumentError, "ENV['MN_REDIS_URL'] is required" \
|
31
|
+
unless ENV.key? 'MN_REDIS_URL'
|
32
|
+
raise ArgumentError, "ENV['COOKIE_DOMAIN'] is required" \
|
33
|
+
unless ENV.key? 'COOKIE_DOMAIN'
|
26
34
|
return RequestStore.store[:sso] if RequestStore.store[:sso]
|
27
35
|
return nil if cookies.nil? || cookies[SSO_COOKIE_NAME].nil? || redis_server.nil?
|
28
|
-
json = redis_server.get(cookies[SSO_COOKIE_NAME]
|
36
|
+
json = redis_server.get(cookies[SSO_COOKIE_NAME])
|
29
37
|
return nil if json.nil?
|
30
38
|
parsed = JSON.parse(json, symbolize_names: true)
|
31
39
|
return nil unless parsed.is_a?(Hash)
|
@@ -36,21 +44,32 @@ module MnUtilsAuth
|
|
36
44
|
nil
|
37
45
|
end
|
38
46
|
|
39
|
-
def set_sso(cookies, user_id, other_attributes = {})
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
def set_sso(cookies, user_id, persistent, other_attributes = {})
|
48
|
+
raise ArgumentError, "ENV['MN_REDIS_URL'] is required" \
|
49
|
+
unless ENV.key? 'MN_REDIS_URL'
|
50
|
+
raise ArgumentError, "ENV['COOKIE_DOMAIN'] is required" \
|
51
|
+
unless ENV.key? 'COOKIE_DOMAIN'
|
52
|
+
return if cookies.nil? || user_id.blank? || RequestStore.store[:sso] || redis_server.nil?
|
53
|
+
value = other_attributes.reverse_merge({ user_id: user_id })
|
54
|
+
redis_ttl = (persistent) ? 1.year.to_i : 1.day.to_i
|
43
55
|
if cookies[SSO_COOKIE_NAME].nil?
|
44
|
-
|
45
|
-
cookie
|
46
|
-
@logger.debug "in set_sso 4 #{cookie}"
|
47
|
-
value = other_attributes.reverse_merge({ user_id: user_id })
|
48
|
-
redis_server.set(cookie, JSON[value])
|
56
|
+
cookie = set_sso_cookie cookies, persistent
|
57
|
+
redis_server.set(cookie, JSON[value], ex: redis_ttl)
|
49
58
|
RequestStore.store[:sso] = value
|
59
|
+
else
|
60
|
+
if !redis_server.get(cookies[SSO_COOKIE_NAME])
|
61
|
+
cookie = set_sso_cookie cookies, persistent
|
62
|
+
redis_server.set(cookie, JSON[value], ex: redis_ttl)
|
63
|
+
RequestStore.store[:sso] = value
|
64
|
+
end
|
50
65
|
end
|
51
66
|
end
|
52
67
|
|
53
68
|
def delete_sso(cookies)
|
69
|
+
raise ArgumentError, "ENV['MN_REDIS_URL'] is required" \
|
70
|
+
unless ENV.key? 'MN_REDIS_URL'
|
71
|
+
raise ArgumentError, "ENV['COOKIE_DOMAIN'] is required" \
|
72
|
+
unless ENV.key? 'COOKIE_DOMAIN'
|
54
73
|
if cookies[SSO_COOKIE_NAME]
|
55
74
|
redis_server.del(cookies[SSO_COOKIE_NAME])
|
56
75
|
cookies.delete SSO_COOKIE_NAME
|
@@ -62,10 +81,12 @@ module MnUtilsAuth
|
|
62
81
|
|
63
82
|
private
|
64
83
|
|
65
|
-
def set_sso_cookie(cookies)
|
84
|
+
def set_sso_cookie(cookies, persistent)
|
85
|
+
expiry = persistent ? 1.year.from_now : 1.day.from_now
|
66
86
|
cookies[SSO_COOKIE_NAME] = {
|
67
87
|
value: cookie_value,
|
68
|
-
|
88
|
+
domain: ENV['COOKIE_DOMAIN'],
|
89
|
+
expires: expiry,
|
69
90
|
secure: true,
|
70
91
|
httponly: true
|
71
92
|
}
|
data/lib/mn_utils_gem/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mn_utils_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shamim Mirzai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gelf
|