oauth_im 0.7.3 → 0.8.1

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: f4b28f51bcd7b2893dd52780a267678fab317eb70feefa6d3ab9d714cad45834
4
- data.tar.gz: c605bb66ede19ea12e1e124f12164d3cee63358d24a0bd0971693732e96b380f
3
+ metadata.gz: 8208d820c7e100554ecce30e7059fd4d082679a90875a6345a19cb072c010f2c
4
+ data.tar.gz: 4210b53980b4d73a75bd4a48ec5318d2369e22e7d3db15253b5d706dd4c46821
5
5
  SHA512:
6
- metadata.gz: a61461548d89152f21df67bdafc810ff7e38826e070a61185a5b557c28c42d3477fc92acf1de2e256d0a6349a1a8c6923248bda1586c7303fe5f77aa5d1a2c4f
7
- data.tar.gz: 3c4db160ded76f36e56ed22791f404741b43cc1b204c8221f09852c0ab3ca71b7c9cbd0ed28a5a0d298b7d855becc841efb768e5578359057db8d8cc062208d3
6
+ metadata.gz: 38d9767641f6b8b691cfc1ceaabac18db7bfdade8f04d4110d669c3c5b48f9e0a501931c859650d7976f458225233e97eb475f92b8dcb2ca9b2b66488c596cfc
7
+ data.tar.gz: 2ed159a29e9164d3aec610e20559a65fe6386e065945b942f7b1dded21a4aac0bc7f38ac2333b2a0a529134273286700dff636a65ba75518ee1586cd677ff0cb
data/README.md CHANGED
@@ -40,16 +40,23 @@ 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
- # View default signing key: https://illustrativemath-dev.fusionauth.io/admin/key/ #
51
- ###################################################################################
49
+ #################################################################################
50
+ # 1. Find signing key name on the app details name. #
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
  ```
@@ -104,12 +111,16 @@ end
104
111
  ### Initializer
105
112
  * The gem provides a single initializer, `AppContext`.
106
113
  * This module is **not** name-spaced.
107
- * It provides a single method, `provide_authentication?`, which by
108
- default is `true`.
109
- * Client apps can override this initializer method.
114
+
115
+ #### Methods
116
+ * `AppContext#provide_authentication?` method defaults to `true` and
117
+ can be overridden as required.
110
118
  * For example, `iiab` overrides this initializer so that the
111
- `provide_authentication?` method returns `false` unless the app is
112
- `kh_iiab` (not `demo_im`).
119
+ `provide_authentication?` method returns `false` unless the app
120
+ is `kh_iiab` (not `demo_im`).
121
+ * `AppContext#privileged?` defaults to `nil` and can be overridden as required.
122
+ * `AppContext#authenticate_for_specs` offers a way to mock
123
+ authentication and privilege in specs. It accepts a block.
113
124
 
114
125
  ## Gem Maintenance
115
126
  After many false starts, this repo includes two (seemingly functional) github workflows.
@@ -143,6 +154,16 @@ After many false starts, this repo includes two (seemingly functional) github wo
143
154
 
144
155
  ## Version History
145
156
 
157
+ ### 0.8.1
158
+ * Tightened up test environment helpers.
159
+
160
+ ### 0.8.0
161
+ * Allow RSA signing keys in addition to HMAC.
162
+ This is because Terraform creates RSA keys during runs.
163
+
164
+ ### 0.7.4
165
+ * Use https protocol for callback in production; http otherwise
166
+
146
167
  ### 0.7.3
147
168
  * Cleaned up configuration
148
169
 
@@ -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
- email
40
- else
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
 
@@ -7,8 +7,6 @@ module OauthIm
7
7
  def callback
8
8
  session[:user_jwt] = user_jwt
9
9
  redirect_to main_app.root_path
10
- rescue StandardError
11
- head :forbidden
12
10
  end
13
11
 
14
12
  def login
@@ -49,7 +49,7 @@ module OauthIm
49
49
  end
50
50
 
51
51
  def protocol
52
- @protocol ||= Rails.env.test? ? :http : :https
52
+ @protocol ||= Rails.env.production? ? :https : :http
53
53
  end
54
54
 
55
55
  def decoded_token
@@ -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, hmac, true, decode_params
26
+ @decoded_token ||= JWT.decode token, key, verify?, decode_params
27
27
  end
28
28
 
29
- def decode_algorithm
30
- DEFAULT_DECODE_ALGORITHM
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: decode_algorithm }.freeze
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.authenticated_for_specs?
9
- @authenticated_for_specs
8
+ def self.privileged?
9
+ @privileged if provide_authentication?
10
10
  end
11
11
 
12
- def self.privileged?
13
- @privileged
12
+ def self.spec_user
13
+ @spec_user if Rails.env.test? && provide_authentication?
14
14
  end
15
15
 
16
- def self.current_user
17
- @current_user
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(current_user: nil, privileged: false)
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
- @current_user = current_user
25
+ @spec_user = spec_user
23
26
  @privileged = privileged
24
27
  yield
25
28
  @privileged = false
26
- @current_user = nil
29
+ @spec_user = nil
27
30
  @authenticated_for_specs = false
28
31
  end
29
32
  end
@@ -15,6 +15,7 @@ module OauthIm
15
15
  client_id
16
16
  client_secret
17
17
  hmac
18
+ rsa_public
18
19
  ].freeze
19
20
 
20
21
  class Configuration
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OauthIm
4
- VERSION = '0.7.3'
4
+ VERSION = '0.8.1'
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.7.3
4
+ version: 0.8.1
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-05-24 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt