oauth_im 0.9.4 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/oauth_im/authenticable.rb +2 -2
- data/app/services/oauth_im/admin_client.rb +37 -0
- data/app/services/oauth_im/has_registration_data.rb +41 -0
- data/app/services/oauth_im/proxy_user.rb +32 -0
- data/app/services/oauth_im/user_client.rb +6 -13
- data/lib/oauth_im/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 261d1ea644c2e1b82d42840d636d8f30e1ffe9dfb719a85c690440e192eec6a6
|
4
|
+
data.tar.gz: 1310fdeb14e9182818d4905c8c82a98e5d7c89e6033c448d58f013eaf3d1851d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f670809fb571009b1281e7a896ae0a6d733eff593974243d2982cd8f8b06ea5958ab9501e05e2bb5f313d0999e7dbfdd97e7f20e2e8ccc71f89f1569e080d404
|
7
|
+
data.tar.gz: 5a63f7ff9a3b0e9a7f7ddc9c2375c64c3be0536bac627c550d1da29b10be61a4ab301e107873b689bf1883ecb8494b87e003526c5ab1cd0dd2e5174b34972f46
|
@@ -5,14 +5,14 @@ module OauthIm
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
helper_method :authenticated
|
9
|
-
helper_method :email
|
8
|
+
helper_method :admin?, :authenticated?, :email
|
10
9
|
end
|
11
10
|
|
12
11
|
private
|
13
12
|
|
14
13
|
delegate :email, :email_verified?,
|
15
14
|
:user_is_sponsor?,
|
15
|
+
:admin?,
|
16
16
|
to: :user_client,
|
17
17
|
allow_nil: true
|
18
18
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fusionauth/fusionauth_client'
|
4
|
+
|
5
|
+
module OauthIm
|
6
|
+
class AdminClient < IdpClient
|
7
|
+
def search_for(term: '', email: '')
|
8
|
+
if email.present?
|
9
|
+
proxy_users_for client.retrieve_user_by_email(email)
|
10
|
+
elsif term.present?
|
11
|
+
proxy_users_for client.search_users_by_query({ search: { queryString: term } })
|
12
|
+
else
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def proxy_user_for(user_id:)
|
18
|
+
response = client.retrieve_user(user_id).success_response
|
19
|
+
raise "No user for id #{user_id}" if response.blank?
|
20
|
+
|
21
|
+
ProxyUser.new response.user
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def user_attrs_for(response)
|
27
|
+
response.success_response.then do |results|
|
28
|
+
results&.users.presence ||
|
29
|
+
[results&.user.presence].compact
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def proxy_users_for(response)
|
34
|
+
user_attrs_for(response).map { |attrs| ProxyUser.new(attrs) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fusionauth/fusionauth_client'
|
4
|
+
|
5
|
+
module OauthIm
|
6
|
+
module HasRegistrationData
|
7
|
+
delegate :email, to: :attrs
|
8
|
+
delegate :role, :grade_level, :school, :district, :state,
|
9
|
+
to: :registration_data
|
10
|
+
delegate :name, :id,
|
11
|
+
to: :role, prefix: true
|
12
|
+
delegate :name, :id,
|
13
|
+
to: :grade_level, prefix: true
|
14
|
+
delegate :name, :id,
|
15
|
+
to: :school, prefix: true
|
16
|
+
delegate :name, :id,
|
17
|
+
to: :district, prefix: true
|
18
|
+
delegate :name, :id,
|
19
|
+
to: :state, prefix: true
|
20
|
+
|
21
|
+
def registration_data
|
22
|
+
@registration_data ||= attrs[:registrations]&.first&.data || {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def sponsor?
|
26
|
+
registration_data[:sponsor].eql? 'true'
|
27
|
+
end
|
28
|
+
|
29
|
+
def user_is_sponsor?
|
30
|
+
sponsor?
|
31
|
+
end
|
32
|
+
|
33
|
+
def first_name
|
34
|
+
attrs.firstName
|
35
|
+
end
|
36
|
+
|
37
|
+
def last_name
|
38
|
+
attrs.lastName
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OauthIm
|
4
|
+
class ProxyUser < IdpClient
|
5
|
+
include HasRegistrationData
|
6
|
+
|
7
|
+
attr_reader :attrs
|
8
|
+
|
9
|
+
delegate :to_h, to: :attrs
|
10
|
+
|
11
|
+
def self.for(user_id:)
|
12
|
+
AdminClient.new.proxy_user_for user_id: user_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(attrs)
|
16
|
+
@attrs = attrs
|
17
|
+
super()
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_id
|
21
|
+
@user_id ||= attrs[:id]
|
22
|
+
end
|
23
|
+
|
24
|
+
def send_reset_password_email
|
25
|
+
client.forgot_password loginId: user_id
|
26
|
+
end
|
27
|
+
|
28
|
+
def deactivate_user
|
29
|
+
client.deactivate_user user_id
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -4,6 +4,8 @@ require 'fusionauth/fusionauth_client'
|
|
4
4
|
|
5
5
|
module OauthIm
|
6
6
|
class UserClient < IdpClient
|
7
|
+
include HasRegistrationData
|
8
|
+
|
7
9
|
attr_reader :user_jwt
|
8
10
|
|
9
11
|
def initialize(user_jwt:)
|
@@ -19,29 +21,20 @@ module OauthIm
|
|
19
21
|
email.present?
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
23
|
-
|
24
|
+
def admin?
|
25
|
+
jwt_token[:roles].include? 'admin'
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
def
|
29
|
-
@
|
30
|
-
end
|
31
|
-
|
32
|
-
def data
|
33
|
-
@data ||= user_data[:data] || {}
|
30
|
+
def attrs
|
31
|
+
@attrs ||= success_response[:user] || {}
|
34
32
|
end
|
35
33
|
|
36
34
|
def success_response
|
37
35
|
@success_response ||= client_response&.success_response || {}
|
38
36
|
end
|
39
37
|
|
40
|
-
def user
|
41
|
-
@user ||= success_response[:user] || {}
|
42
|
-
end
|
43
|
-
|
44
|
-
# https://www.rubydoc.info/gems/fusionauth_client/1.32.1/FusionAuth/FusionAuthClient#retrieve_user-instance_method
|
45
38
|
def client_response
|
46
39
|
@client_response ||= client.retrieve_user user_id
|
47
40
|
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.
|
4
|
+
version: 0.10.0
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fusionauth_client
|
@@ -139,8 +139,11 @@ files:
|
|
139
139
|
- app/controllers/oauth_im/application_controller.rb
|
140
140
|
- app/controllers/oauth_im/client_controller.rb
|
141
141
|
- app/helpers/oauth_im/application_helper.rb
|
142
|
+
- app/services/oauth_im/admin_client.rb
|
142
143
|
- app/services/oauth_im/client.rb
|
144
|
+
- app/services/oauth_im/has_registration_data.rb
|
143
145
|
- app/services/oauth_im/idp_client.rb
|
146
|
+
- app/services/oauth_im/proxy_user.rb
|
144
147
|
- app/services/oauth_im/registration_client.rb
|
145
148
|
- app/services/oauth_im/request_client.rb
|
146
149
|
- app/services/oauth_im/token_decoder.rb
|