oauth_im 0.7.2 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa5dbaae2a3e5884523e938a1a2c1a5009297260c2ced57a69eb6b9b43bc0116
4
- data.tar.gz: 5d80271d7c2aa8d9baa53119180c7889da5c47f30f51cf92d8f0aa2f1c2e5376
3
+ metadata.gz: be1d2aa7d9e5c1ac97a5e5aabd89671a48bfc2afc17c53276f961be0a29d357e
4
+ data.tar.gz: 64f150ae67c0b67efd6a8db20c1390bb69ca21f29837446ad07264947e8e863d
5
5
  SHA512:
6
- metadata.gz: 873154c1389b866c7d68d209d6bf83e107c7db64e01ab0bffcba9578ad5f6e0df22ea91a66fda1dd67ee9675ad18c330716c7572b772e9e721a241e5a473369c
7
- data.tar.gz: 8e1c2d0c1ef24d23f4348788fee37befbf216af10b9425f4dc861739dc745ab57db76b3c7b0a3d8869457aa1b701d7a5fe6940358a47ec104fe7aca9027fb9b0
6
+ metadata.gz: 11624bb0650c05d8a5f63edee7b8918f6e043f6a4b6d15b25cd593da5940af18ab320a5d4587479ab96c836ef60b99b4e45f49fabfe3a08e23870dd1d1489499
7
+ data.tar.gz: 4018866ef76985ec65ccb37ab95e7e973caf0e8f07086a25ad3f55b2eb17659d130e75421466f60f8d526aa8929239c935d87fb905d7358edfceae6c81540ff5
data/README.md CHANGED
@@ -23,20 +23,46 @@ Once the gem is installed, add an initializer. Here is an example:
23
23
  # config/initializers/oauth_im.rb
24
24
  module OauthIm
25
25
  configure do |config|
26
- config.api_key = ENV['FUSION_AUTH_API_KEY']
27
- config.callback_route = ENV['FUSION_CALLBACK_ROUTE] || DEFAULT_CALLBACK_ROUTE
26
+ #####################################
27
+ # these routes are local to the app #
28
+ #####################################
29
+ config.authorize_url = ENV.fetch 'FUSION_AUTH_AUTHORIZE_URL', DEFAULT_AUTHORIZE_URL
30
+ config.callback_route = ENV.fetch 'FUSION_CALLBACK_ROUTE', DEFAULT_CALLBACK_ROUTE
31
+ config.token_url = ENV.fetch 'FUSION_AUTH_TOKEN_URL', DEFAULT_TOKEN_URL
32
+
33
+ ##############################################
34
+ # identity provider url (e.g., fusion auth): #
35
+ ##############################################
36
+ config.idp_url = ENV.fetch 'FUSION_AUTH_IDP_URL', DEFAULT_IDP_URL
37
+
38
+ ################################################
39
+ # Issuer domain: find on FA tenant General tab #
40
+ ################################################
41
+ config.iss_domain = ENV.fetch 'FUSION_AUTH_ISS_DOMAIN', DEFAULT_ISS_DOMAIN
42
+
43
+ ####################################
44
+ # find on FA application OAuth tab #
45
+ ####################################
28
46
  config.client_id = ENV['FUSION_AUTH_CLIENT_ID']
29
47
  config.client_secret = ENV['FUSION_AUTH_CLIENT_SECRET']
30
- config.domain = ENV['FUSION_AUTH_DOMAIN']
48
+
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
+ #################################################################################
31
58
  config.hmac = ENV['FUSION_AUTH_HMAC']
32
- config.iss_domain = ENV['FUSION_AUTH_ISS_DOMAIN']
33
- config.authorize_url = ENV['FUSION_AUTH_AUTHORIZE_URL'] || DEFAULT_AUTHORIZE_URL
34
- config.token_url = ENV['FUSION_AUTH_TOKEN_URL'] || DEFAULT_TOKEN_URL
59
+ config.rsa_public = ENV['FUSION_AUTH_RSA_PUBLIC]
35
60
  end
36
61
  end
37
62
  ```
38
63
 
39
64
  * The `ENV` variable values can be obtained from the OAuth provider.
65
+ * Here is [an article at FusionAuth](https://fusionauth.io/blog/2020/12/14/how-to-securely-implement-oauth-rails) describing many of these settings.
40
66
  * The `callback_route` setting is used in two related ways:
41
67
  * It [defines a route](https://github.com/illustrativemathematics/oauth_im/blob/main/config/routes.rb#L4) to the [`OAuthIm::ClientController#callback`
42
68
  action](https://github.com/illustrativemathematics/oauth_im/blob/main/app/controllers/oauth_im/client_controller.rb#L7-L12).
@@ -54,9 +80,9 @@ end
54
80
  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
55
81
  corresponding view helpers. These are accessible from the main app as:
56
82
 
57
- | path | url |
58
- |------|-----|
59
- | `oauth_im.login_path` | `oauth_im.login_url` |
83
+ | path | url |
84
+ |------------------------|-----------------------|
85
+ | `oauth_im.login_path` | `oauth_im.login_url` |
60
86
  | `oauth_im.logout_path` | `oauth_im.logout_url` |
61
87
 
62
88
  * Note that the helpers are namespaced to the engine.
@@ -123,6 +149,14 @@ After many false starts, this repo includes two (seemingly functional) github wo
123
149
  you.
124
150
 
125
151
  ## Version History
152
+ ### 0.8.0
153
+ * Allow RSA signing keys in addition to HMAC.
154
+ This is because Terraform creates RSA keys during runs.
155
+ ### 0.7.4
156
+ * Use https protocol for callback in production; http otherwise
157
+
158
+ ### 0.7.3
159
+ * Cleaned up configuration
126
160
 
127
161
  ### 0.7.2
128
162
  * Using :http protocol in tests (not https)
@@ -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
@@ -13,7 +13,7 @@ module OauthIm
13
13
  end
14
14
 
15
15
  def logout_url
16
- @logout_url ||= "#{domain}/oauth2/logout" \
16
+ @logout_url ||= "#{idp_url}/oauth2/logout" \
17
17
  "?post_logout_redirect_uri=#{return_to_url}" \
18
18
  "&client_id=#{client_id}"
19
19
  end
@@ -26,7 +26,7 @@ module OauthIm
26
26
 
27
27
  delegate :host_with_port, :params, to: :request
28
28
  delegate :configuration, to: OauthIm
29
- delegate :authorize_url, :client_id, :client_secret, :domain, :token_url,
29
+ delegate :authorize_url, :token_url, :idp_url, :client_id, :client_secret,
30
30
  to: :configuration
31
31
  delegate :auth_code, to: :oauth_client
32
32
 
@@ -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
@@ -64,7 +64,7 @@ module OauthIm
64
64
  @oauth_client ||= ::OAuth2::Client.new client_id,
65
65
  client_secret,
66
66
  authorize_url: authorize_url,
67
- site: domain,
67
+ site: idp_url,
68
68
  token_url: token_url,
69
69
  redirect_uri: redirect_url
70
70
  end
@@ -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
@@ -1,16 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ########################################################################################
4
+ # edc: see https://fusionauth.io/blog/2020/12/14/how-to-securely-implement-oauth-rails #
5
+ ########################################################################################
6
+
3
7
  module OauthIm
4
8
  CONFIGURABLE_FIELDS =
5
- %i[api_key
6
- authorize_url
7
- callback_route
8
- client_id
9
- client_secret
10
- domain
11
- hmac
12
- iss_domain
13
- token_url].freeze
9
+ %i[
10
+ authorize_url
11
+ callback_route
12
+ token_url
13
+ idp_url
14
+ iss_domain
15
+ client_id
16
+ client_secret
17
+ hmac
18
+ rsa_public
19
+ ].freeze
14
20
 
15
21
  class Configuration
16
22
  attr_reader(* CONFIGURABLE_FIELDS)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OauthIm
4
- VERSION = '0.7.2'
4
+ VERSION = '0.8.0'
5
5
  end
data/lib/oauth_im.rb CHANGED
@@ -1,13 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ########################################################################################
4
+ # edc: see https://fusionauth.io/blog/2020/12/14/how-to-securely-implement-oauth-rails #
5
+ ########################################################################################
6
+
3
7
  require 'oauth_im/version'
4
8
  require 'oauth_im/engine'
5
9
  require 'oauth_im/configuration'
6
10
 
7
11
  module OauthIm
8
12
  DEFAULT_AUTHORIZE_URL = '/oauth2/authorize'
9
- DEFAULT_TOKEN_URL = '/oauth2/token'
10
13
  DEFAULT_CALLBACK_ROUTE = 'callback'
14
+ DEFAULT_TOKEN_URL = '/oauth2/token'
15
+ DEFAULT_IDP_URL = 'https://illustrativemath-dev.fusionauth.io'
16
+ DEFAULT_ISS_DOMAIN = 'illustrativemathematics.org'
11
17
 
12
18
  class << self
13
19
  attr_reader :configuration
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.2
4
+ version: 0.8.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-05-24 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt