oauth_im 0.7.4 → 0.8.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 +4 -4
- data/README.md +59 -12
- data/app/controllers/concerns/oauth_im/authenticable.rb +3 -7
- data/app/controllers/oauth_im/client_controller.rb +0 -2
- data/app/services/oauth_im/token_decoder.rb +21 -5
- data/config/initializers/app_context.rb +12 -9
- data/lib/oauth_im/configuration.rb +1 -0
- data/lib/oauth_im/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: 7c32ade2f9c543728b3946076d1f8cad2566f06f4959c20b7c67613b6c296240
|
4
|
+
data.tar.gz: ad6148ef5c4bed447ee4468ef03825a5802b9df3f3a0dd096bda20f4024b803a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4824f3121b1ee2e24c0f706041c0295335a9efd35317442c5e1c857836224b88713ee61d1d1ae0694d01acd8559ef363ad44047393bb2b00128af96a97b60603
|
7
|
+
data.tar.gz: 656cbad5b4111347e5b0f277fcb99d9ac794fc8defccc1d49cb0637d1971d21f900315ab731f6d3eec16b9606f4b2de2902028d8a6bb8ddc13630a74aa261b78
|
data/README.md
CHANGED
@@ -40,21 +40,30 @@ module OauthIm
|
|
40
40
|
################################################
|
41
41
|
config.iss_domain = ENV.fetch 'FUSION_AUTH_ISS_DOMAIN', DEFAULT_ISS_DOMAIN
|
42
42
|
|
43
|
-
|
44
|
-
# on FA application OAuth tab #
|
45
|
-
|
43
|
+
####################################
|
44
|
+
# find on FA application OAuth tab #
|
45
|
+
####################################
|
46
46
|
config.client_id = ENV['FUSION_AUTH_CLIENT_ID']
|
47
47
|
config.client_secret = ENV['FUSION_AUTH_CLIENT_SECRET']
|
48
48
|
|
49
|
-
|
50
|
-
#
|
51
|
-
|
49
|
+
####################################################################################
|
50
|
+
# 1. Find signing key name on the app details pane. (See RSA v. HMAC screenshots.) #
|
51
|
+
# 2. Look up the key (by name) under Key Master tab under Settings: #
|
52
|
+
# https://illustrativemath-dev.fusionauth.io/admin/key/ #
|
53
|
+
# 3. The key should be either HMAC or RSA. #
|
54
|
+
# - If HMAC, view the Secret under Details. You will need to click to reveal. #
|
55
|
+
# - If RSA, copy the PEM encoded public key as-is. #
|
56
|
+
# Note: You don't need both keys --- TokenDecoder will use the one available. #
|
57
|
+
####################################################################################
|
52
58
|
config.hmac = ENV['FUSION_AUTH_HMAC']
|
59
|
+
config.rsa_public = ENV['FUSION_AUTH_RSA_PUBLIC]
|
53
60
|
end
|
54
61
|
end
|
55
62
|
```
|
56
63
|
|
57
|
-
|
64
|
+
### Environment
|
65
|
+
|
66
|
+
The `ENV` variable values can be obtained from the OAuth provider.
|
58
67
|
* Here is [an article at FusionAuth](https://fusionauth.io/blog/2020/12/14/how-to-securely-implement-oauth-rails) describing many of these settings.
|
59
68
|
* The `callback_route` setting is used in two related ways:
|
60
69
|
* It [defines a route](https://github.com/illustrativemathematics/oauth_im/blob/main/config/routes.rb#L4) to the [`OAuthIm::ClientController#callback`
|
@@ -68,7 +77,30 @@ end
|
|
68
77
|
must be entered in the OAuth provider's list of authorized
|
69
78
|
redirect URLs.
|
70
79
|
|
80
|
+
### RSA v. HMAC
|
81
|
+
|
82
|
+
To determine the access token signing key, find the name of the key and then look it up
|
83
|
+
on the Settings|Key Master pane. (See screenshots.)
|
84
|
+
|
85
|
+
* Inspect your app settings. The screenshot shows this being done for the app
|
86
|
+
`Kendall Hunt - Terraform`.
|
87
|
+
|
88
|
+

|
89
|
+
|
90
|
+
* Find the name of the token. The screenshot shows this being done for the app
|
91
|
+
`Kendall Hunt - Terraform`. You will need to scroll down the page to the `JWT` section.
|
92
|
+
|
93
|
+

|
94
|
+
|
95
|
+
* Look up this signing token under Home|Settings|Key Master. The screenshot shows this being done
|
96
|
+
for the signing token `KendallHunt-Terraform (12)`.
|
97
|
+
* For RSA tokens like this one, use the PEM encoded public key as-is.
|
98
|
+
* For HMAC tokens, view the secret under Details (click to reveal).
|
99
|
+
|
100
|
+

|
101
|
+
|
71
102
|
## Usage
|
103
|
+
|
72
104
|
### Helpers for Logging in and Out
|
73
105
|
The engine provides [two endpoints](https://github.com/illustrativemathematics/oauth_im/blob/main/config/routes.rb#L5-L6) for logging in and out, and exposes
|
74
106
|
corresponding view helpers. These are accessible from the main app as:
|
@@ -104,12 +136,16 @@ end
|
|
104
136
|
### Initializer
|
105
137
|
* The gem provides a single initializer, `AppContext`.
|
106
138
|
* This module is **not** name-spaced.
|
107
|
-
|
108
|
-
|
109
|
-
*
|
139
|
+
|
140
|
+
#### Methods
|
141
|
+
* `AppContext#provide_authentication?` method defaults to `true` and
|
142
|
+
can be overridden as required.
|
110
143
|
* For example, `iiab` overrides this initializer so that the
|
111
|
-
`provide_authentication?` method returns `false` unless the app
|
112
|
-
`kh_iiab` (not `demo_im`).
|
144
|
+
`provide_authentication?` method returns `false` unless the app
|
145
|
+
is `kh_iiab` (not `demo_im`).
|
146
|
+
* `AppContext#privileged?` defaults to `nil` and can be overridden as required.
|
147
|
+
* `AppContext#authenticate_for_specs` offers a way to mock
|
148
|
+
authentication and privilege in specs. It accepts a block.
|
113
149
|
|
114
150
|
## Gem Maintenance
|
115
151
|
After many false starts, this repo includes two (seemingly functional) github workflows.
|
@@ -142,6 +178,17 @@ After many false starts, this repo includes two (seemingly functional) github wo
|
|
142
178
|
you.
|
143
179
|
|
144
180
|
## Version History
|
181
|
+
|
182
|
+
### 0.8.2
|
183
|
+
* README
|
184
|
+
|
185
|
+
### 0.8.1
|
186
|
+
* Tightened up test environment helpers.
|
187
|
+
|
188
|
+
### 0.8.0
|
189
|
+
* Allow RSA signing keys in addition to HMAC.
|
190
|
+
This is because Terraform creates RSA keys during runs.
|
191
|
+
|
145
192
|
### 0.7.4
|
146
193
|
* Use https protocol for callback in production; http otherwise
|
147
194
|
|
@@ -35,13 +35,9 @@ module OauthIm
|
|
35
35
|
def current_user
|
36
36
|
@current_user ||=
|
37
37
|
if user_jwt.present?
|
38
|
-
if email_verified?
|
39
|
-
|
40
|
-
|
41
|
-
head :forbidden
|
42
|
-
end
|
43
|
-
else
|
44
|
-
AppContext.current_user
|
38
|
+
email if email_verified?
|
39
|
+
elsif Rails.env.test?
|
40
|
+
AppContext.spec_user
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
@@ -20,14 +20,30 @@ module OauthIm
|
|
20
20
|
private
|
21
21
|
|
22
22
|
delegate :configuration, to: OauthIm
|
23
|
-
delegate :hmac, :iss_domain, to: :configuration
|
23
|
+
delegate :hmac, :rsa_public, :iss_domain, to: :configuration
|
24
24
|
|
25
25
|
def decoded_token
|
26
|
-
@decoded_token ||= JWT.decode token,
|
26
|
+
@decoded_token ||= JWT.decode token, key, verify?, decode_params
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def decode_using_hmac?
|
30
|
+
hmac.present?
|
31
|
+
end
|
32
|
+
|
33
|
+
def key
|
34
|
+
@key ||= decode_using_hmac? ? hmac : rsa_public_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def rsa_public_key
|
38
|
+
@rsa_public_key ||= OpenSSL::PKey::RSA.new rsa_public
|
39
|
+
end
|
40
|
+
|
41
|
+
def algorithm
|
42
|
+
@algorithm ||= decode_using_hmac? ? 'HS256' : 'RS256'
|
43
|
+
end
|
44
|
+
|
45
|
+
def verify?
|
46
|
+
true
|
31
47
|
end
|
32
48
|
|
33
49
|
def verify_iss?
|
@@ -43,7 +59,7 @@ module OauthIm
|
|
43
59
|
iss: iss_domain,
|
44
60
|
verify_aud: verify_aud?,
|
45
61
|
aud: aud,
|
46
|
-
algorithm:
|
62
|
+
algorithm: algorithm }.freeze
|
47
63
|
end
|
48
64
|
end
|
49
65
|
end
|
@@ -5,25 +5,28 @@ module AppContext
|
|
5
5
|
true
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.
|
9
|
-
@
|
8
|
+
def self.privileged?
|
9
|
+
@privileged if provide_authentication?
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.
|
13
|
-
@
|
12
|
+
def self.spec_user
|
13
|
+
@spec_user if Rails.env.test? && provide_authentication?
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
17
|
-
@
|
16
|
+
def self.authenticated_for_specs?
|
17
|
+
@authenticated_for_specs if Rails.env.test? && provide_authentication?
|
18
18
|
end
|
19
19
|
|
20
|
-
def self.authenticate_for_specs(
|
20
|
+
def self.authenticate_for_specs(spec_user: nil, privileged: false)
|
21
|
+
return unless provide_authentication?
|
22
|
+
raise 'Use only in test environment!!' unless Rails.env.test?
|
23
|
+
|
21
24
|
@authenticated_for_specs = true
|
22
|
-
@
|
25
|
+
@spec_user = spec_user
|
23
26
|
@privileged = privileged
|
24
27
|
yield
|
25
28
|
@privileged = false
|
26
|
-
@
|
29
|
+
@spec_user = nil
|
27
30
|
@authenticated_for_specs = false
|
28
31
|
end
|
29
32
|
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.8.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-
|
11
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|