oauth_im 0.9.2 → 0.10.0
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 +4 -4
- data/README.md +3 -0
- data/app/controllers/concerns/oauth_im/authenticable.rb +8 -6
- 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/config/initializers/app_context.rb +37 -16
- 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
|
data/README.md
CHANGED
@@ -139,6 +139,9 @@ After many false starts, this repo includes two (seemingly functional) github wo
|
|
139
139
|
|
140
140
|
## Version History
|
141
141
|
|
142
|
+
### 0.9.3
|
143
|
+
* added specs for AppContext initializer
|
144
|
+
|
142
145
|
### 0.9.2
|
143
146
|
* Fix redirect url
|
144
147
|
* No longer does it take user back to page they were on
|
@@ -5,17 +5,19 @@ 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
|
|
19
|
+
delegate :spec_user, :spec_user_is_sponsor?, to: AppContext
|
20
|
+
|
19
21
|
def authenticated?
|
20
22
|
AppContext.authenticated_for_specs? ||
|
21
23
|
(AppContext.provide_authentication? && logged_in?)
|
@@ -32,10 +34,10 @@ module OauthIm
|
|
32
34
|
|
33
35
|
def current_user
|
34
36
|
@current_user ||=
|
35
|
-
if
|
37
|
+
if Rails.env.test?
|
38
|
+
spec_user
|
39
|
+
elsif user_jwt.present?
|
36
40
|
email if email_verified?
|
37
|
-
elsif Rails.env.test?
|
38
|
-
AppContext.spec_user
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -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
|
@@ -1,36 +1,57 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module AppContext
|
4
|
-
|
4
|
+
module_function
|
5
|
+
|
6
|
+
TEST_ENV_ERROR_MESSAGE = 'Use only in test environment!'
|
7
|
+
|
8
|
+
def override_for_specs?
|
9
|
+
Rails.env.test? && provide_authentication?
|
10
|
+
end
|
11
|
+
|
12
|
+
def provide_authentication?
|
5
13
|
true
|
6
14
|
end
|
7
15
|
|
8
|
-
def
|
16
|
+
def provide_auth_routes?
|
17
|
+
provide_authentication?
|
18
|
+
end
|
19
|
+
|
20
|
+
def spec_user
|
9
21
|
@spec_user if override_for_specs?
|
10
22
|
end
|
11
23
|
|
12
|
-
def
|
13
|
-
@
|
24
|
+
def spec_user_is_sponsor?
|
25
|
+
@spec_user_is_sponsor && override_for_specs?
|
14
26
|
end
|
15
27
|
|
16
|
-
def
|
17
|
-
|
28
|
+
def authenticated_for_specs?
|
29
|
+
@authenticated_for_specs && override_for_specs?
|
18
30
|
end
|
19
31
|
|
20
|
-
def
|
21
|
-
Rails.env.test?
|
32
|
+
def authenticate_for_specs?
|
33
|
+
raise TEST_ENV_ERROR_MESSAGE unless Rails.env.test?
|
34
|
+
|
35
|
+
provide_authentication?
|
22
36
|
end
|
23
37
|
|
24
|
-
def
|
25
|
-
return unless
|
26
|
-
raise 'Use only in test environment!!' unless Rails.env.test?
|
38
|
+
def authenticate_for_specs(spec_user: nil, sponsor: false)
|
39
|
+
return unless authenticate_for_specs?
|
27
40
|
|
28
|
-
|
29
|
-
@spec_user = spec_user
|
30
|
-
@spec_user_data = spec_user_data
|
41
|
+
initialize_spec_user spec_user: spec_user, sponsor: sponsor
|
31
42
|
yield
|
32
|
-
|
33
|
-
|
43
|
+
reset_spec_user
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize_spec_user(spec_user:, sponsor:)
|
47
|
+
@spec_user = spec_user
|
48
|
+
@spec_user_is_sponsor = sponsor
|
49
|
+
@authenticated_for_specs = true
|
50
|
+
end
|
51
|
+
|
52
|
+
def reset_spec_user
|
34
53
|
@authenticated_for_specs = false
|
54
|
+
@spec_user = nil
|
55
|
+
@spec_user_is_sponsor = false
|
35
56
|
end
|
36
57
|
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-07
|
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
|