oauth_im 0.9.4 → 0.10.2

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: 3de11fe5ca4fd11cd2d762e7cde0501b1d2f05310991efe187d20b9f035834e1
4
- data.tar.gz: c80dd50d7c7c7f0c1b32f0aab6f9fad43f4a42e0d841d7efd3523786b7710cb9
3
+ metadata.gz: 3157351b7b2f1b010967a23541e3661835a7dc600a4e37d75d26f512e71169d6
4
+ data.tar.gz: b54781e3b5e79d8f167a09e9d1c36e09a4f975a3bf47d2a8279d9fb0adb8be74
5
5
  SHA512:
6
- metadata.gz: b9a6298a624e5c4cc51dfda4bd79920d8d729c8cbbdd9f8a7723e95f2e3aac5c69f36fa4d733e18b9b503e65ba9185a37d88362705d8663572f3e5fb60bf02ad
7
- data.tar.gz: 05b8f611dc5f111eca6865d2115b26b44abc0ccab2b582b7f9ed9fbf3e3f70b8f5e0a1930fb557c70772f128394fd057ca90983f2b7f8c4acaac4ce8de9508d7
6
+ metadata.gz: 14694090ee6a56ad6498adeb3980ac65405437953a603507a699eb40d987d9938baadf1e293c58f7c5b0869f2c0bea8fa674eed97eefa9c229ce76c32925d066
7
+ data.tar.gz: 3a03bee203ffc14fc59cf50319fae33d4dbdc4603d93d68a93fe12ca78dd89d2e6b8e1415fa1fca441e39f8108a6f171f7d056cff6618df9b7cefad05f143922
@@ -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,53 @@
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 active?
26
+ attrs.active
27
+ end
28
+
29
+ def sponsor?
30
+ registration_data[:sponsor].eql? 'true'
31
+ end
32
+
33
+ def user_is_sponsor?
34
+ sponsor?
35
+ end
36
+
37
+ def login_id
38
+ email
39
+ end
40
+
41
+ def first_name
42
+ attrs.firstName
43
+ end
44
+
45
+ def last_name
46
+ attrs.lastName
47
+ end
48
+
49
+ def full_name
50
+ @full_name ||= "#{first_name} #{last_name}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,36 @@
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: login_id
26
+ end
27
+
28
+ def deactivate
29
+ client.deactivate_user user_id
30
+ end
31
+
32
+ def reactivate
33
+ client.reactivate_user user_id
34
+ end
35
+ end
36
+ 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 user_is_sponsor?
23
- data[:sponsor].eql?('true')
24
+ def admin?
25
+ jwt_token[:roles].include? 'admin'
24
26
  end
25
27
 
26
28
  private
27
29
 
28
- def user_data
29
- @user_data ||= user[:registrations]&.first || {}
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OauthIm
4
- VERSION = '0.9.4'
4
+ VERSION = '0.10.2'
5
5
  end
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.9.4
4
+ version: 0.10.2
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-06 00:00:00.000000000 Z
11
+ date: 2022-09-08 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