oauth_im 0.10.0 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d12f50a39c1a642f23bcbaa44e9714ca0c6524cfa364e6872a14b41a7ce582
|
4
|
+
data.tar.gz: 1aca1d5f3683936829fa3886c58570ba89095542c6ceb5447c77afdc86e3edd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 567b8a9267a062b6b06d18930d85b94e14eeb8cffc8f4bd25fdbfbbbf4b30de3475c3ace6d2c7defe24a57bd3da4262142e0ab68a622407b9a55b6df04203c09
|
7
|
+
data.tar.gz: fa168d58bf0786d43f04d209e5b6b7bf7b4ac201702f8f0730984bd63e50fecbb748ee2a9e9b17c5b085a9eff85f11c654a0bf26664561216ede2d1e707dcd69
|
@@ -15,10 +15,14 @@ module OauthIm
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def proxy_user_for(user_id:)
|
18
|
+
ProxyUser.new proxy_attrs_for(user_id: user_id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def proxy_attrs_for(user_id:)
|
18
22
|
response = client.retrieve_user(user_id).success_response
|
19
23
|
raise "No user for id #{user_id}" if response.blank?
|
20
24
|
|
21
|
-
|
25
|
+
response.user
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'fusionauth/fusionauth_client'
|
4
4
|
|
5
|
+
############################################################
|
6
|
+
# # EDC: memoizing state for these methods is problematic. #
|
7
|
+
# # without care, an object's local state can diverge from #
|
8
|
+
# # the remote state returned by the API. so for now #
|
9
|
+
# # it seems safest to leave things unmemoized #
|
10
|
+
############################################################
|
11
|
+
|
5
12
|
module OauthIm
|
6
13
|
module HasRegistrationData
|
7
14
|
delegate :email, to: :attrs
|
@@ -18,8 +25,24 @@ module OauthIm
|
|
18
25
|
delegate :name, :id,
|
19
26
|
to: :state, prefix: true
|
20
27
|
|
28
|
+
def registrations
|
29
|
+
attrs[:registrations] || []
|
30
|
+
end
|
31
|
+
|
32
|
+
def registration
|
33
|
+
registrations.first
|
34
|
+
end
|
35
|
+
|
21
36
|
def registration_data
|
22
|
-
|
37
|
+
registration&.data || {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def application_id
|
41
|
+
registration&.applicationId
|
42
|
+
end
|
43
|
+
|
44
|
+
def active?
|
45
|
+
attrs.active
|
23
46
|
end
|
24
47
|
|
25
48
|
def sponsor?
|
@@ -30,6 +53,10 @@ module OauthIm
|
|
30
53
|
sponsor?
|
31
54
|
end
|
32
55
|
|
56
|
+
def login_id
|
57
|
+
email
|
58
|
+
end
|
59
|
+
|
33
60
|
def first_name
|
34
61
|
attrs.firstName
|
35
62
|
end
|
@@ -37,5 +64,9 @@ module OauthIm
|
|
37
64
|
def last_name
|
38
65
|
attrs.lastName
|
39
66
|
end
|
67
|
+
|
68
|
+
def full_name
|
69
|
+
"#{first_name} #{last_name}"
|
70
|
+
end
|
40
71
|
end
|
41
72
|
end
|
@@ -1,32 +1,107 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
############################################################
|
4
|
+
# # EDC: memoizing state for these methods is problematic. #
|
5
|
+
# # without care, an object's local state can diverge from #
|
6
|
+
# # the remote state returned by the API. so for now #
|
7
|
+
# # it seems safest to leave things unmemoized #
|
8
|
+
############################################################
|
9
|
+
|
3
10
|
module OauthIm
|
4
11
|
class ProxyUser < IdpClient
|
5
12
|
include HasRegistrationData
|
6
13
|
|
7
|
-
attr_reader :attrs
|
8
|
-
|
9
|
-
delegate :to_h, to: :attrs
|
10
|
-
|
11
14
|
def self.for(user_id:)
|
12
15
|
AdminClient.new.proxy_user_for user_id: user_id
|
13
16
|
end
|
14
17
|
|
18
|
+
attr_reader :attrs
|
19
|
+
|
15
20
|
def initialize(attrs)
|
16
21
|
@attrs = attrs
|
17
22
|
super()
|
18
23
|
end
|
19
24
|
|
25
|
+
def grant_sponsorship
|
26
|
+
update_registration { |data| data[:sponsor] = 'true' }
|
27
|
+
end
|
28
|
+
|
29
|
+
def revoke_sponsorship
|
30
|
+
update_registration { |data| data[:sponsor] = 'false' }
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_h
|
34
|
+
os_to_h attrs
|
35
|
+
end
|
36
|
+
|
20
37
|
def user_id
|
21
|
-
|
38
|
+
attrs[:id]
|
22
39
|
end
|
23
40
|
|
24
41
|
def send_reset_password_email
|
25
|
-
client.forgot_password loginId:
|
42
|
+
client.forgot_password loginId: login_id
|
43
|
+
reset_attrs
|
26
44
|
end
|
27
45
|
|
28
|
-
def
|
46
|
+
def deactivate
|
29
47
|
client.deactivate_user user_id
|
48
|
+
reset_attrs
|
49
|
+
end
|
50
|
+
|
51
|
+
def reactivate
|
52
|
+
client.reactivate_user user_id
|
53
|
+
reset_attrs
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def update_registration
|
59
|
+
os_to_h(registration_data).then do |data|
|
60
|
+
yield data
|
61
|
+
client.patch_registration user_id, params_for(data)
|
62
|
+
end
|
63
|
+
reset_attrs
|
64
|
+
end
|
65
|
+
|
66
|
+
def params_for(data)
|
67
|
+
{ registration:
|
68
|
+
{ applicationId: application_id,
|
69
|
+
data: data } }
|
70
|
+
end
|
71
|
+
|
72
|
+
def reset_attrs
|
73
|
+
@attrs = AdminClient.new.proxy_attrs_for(user_id: user_id)
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
|
+
########################################################
|
78
|
+
# # EDC: even though the FusionAuth client returns #
|
79
|
+
# # an OpenStruct with nested OpenStruct values, the #
|
80
|
+
# # patch_registration method does not seem to handle #
|
81
|
+
# # nested OpenStruct objects. #
|
82
|
+
# # #
|
83
|
+
# # this method recurses over these structures and #
|
84
|
+
# # turns them into ordinary nested hashes that seem #
|
85
|
+
# # to be correctly handled. #
|
86
|
+
# # #
|
87
|
+
# # see this SO thread for inspiration: #
|
88
|
+
# # https://stackoverflow.com/a/62804063/778174 #
|
89
|
+
########################################################
|
90
|
+
def os_to_h(obj) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
91
|
+
case obj
|
92
|
+
when Hash, OpenStruct # rubocop:disable Style/OpenStructUse
|
93
|
+
obj.to_h.transform_values do |val|
|
94
|
+
case val
|
95
|
+
when OpenStruct then os_to_h(val) # rubocop:disable Style/OpenStructUse
|
96
|
+
when Array
|
97
|
+
val.map { |entry| os_to_h(entry) }
|
98
|
+
else val
|
99
|
+
end
|
100
|
+
end
|
101
|
+
when Array
|
102
|
+
obj.map { |entry| os_to_h(entry) }
|
103
|
+
else obj
|
104
|
+
end
|
30
105
|
end
|
31
106
|
end
|
32
107
|
end
|
data/lib/oauth_im/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth_im
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Connally
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fusionauth_client
|