rodauth-oauth 1.6.2 → 1.6.4

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: a33a9ee71a918fe0ea7e71e63062d9399117081bd6d065e5d00dcd4d73ffe8a3
4
- data.tar.gz: b269c68bb2a1eb45bba20ce222b18184d5e64d83ce3ccba1641403e01d2a2c28
3
+ metadata.gz: 83351fdb82b53fcc94fbafcfe1f3a2057b887b633ae39c4de24a5268136164ec
4
+ data.tar.gz: 6b1d1f26cfc189cb6d18269af0634f358724a156bd26edc514bb008615e55e68
5
5
  SHA512:
6
- metadata.gz: 74221c277a9f55e01447063cbc9f8f0d01bb3b77bedbcb86b7b14ab6baeb50d09cbb556c9e54cf14a50d91460a427a9eaaa1a541f4f2e0e87edd724df28703e8
7
- data.tar.gz: 3fcfe3de3b11791ceea035142344f7bbf88a05082452c77b17c4c6fdfc872b956d44f9d04307e61b476b38b340ee7fc68bd27da3698e402b3b7d75628d7c0008
6
+ metadata.gz: c2197aad8a6e0d0e5d46ef2b18f0730133d06463c1115c60a949b079849c8bb5ab62e1424db5fea1ede68ae5ff1084dfe805a4247164387163a16f8b5f425c40
7
+ data.tar.gz: 63f3c8bfff288028767e833735c8c1496595a9ec08a7c06463df98fe2b93ad987d95e42e0e68c08c24698b97a454924a326d6326c056f41181920c189f04472d
data/README.md CHANGED
@@ -50,6 +50,7 @@ This gem implements the following RFCs and features of OAuth:
50
50
  * `oauth_assertion_base` - [Assertion Framework](https://datatracker.ietf.org/doc/html/rfc7521);
51
51
  * `oauth_saml_bearer_grant` - [SAML 2.0 Bearer Assertion](https://datatracker.ietf.org/doc/html/rfc7522);
52
52
  * `oauth_jwt_bearer_grant` - [JWT Bearer Assertion](https://datatracker.ietf.org/doc/html/rfc7523);
53
+ * `oauth_dpop` - [OAuth 2.0 Demonstrating Proof-of-Possession at the Application Layer (DPoP)](https://datatracker.ietf.org/doc/rfc9449/);
53
54
 
54
55
  * `oauth_dynamic_client_registration` - [Dynamic Client Registration Protocol](https://datatracker.ietf.org/doc/html/rfc7591) and [Dynamic Client Registration Management](https://www.rfc-editor.org/rfc/rfc7592);
55
56
  * OAuth application and token management dashboards;
@@ -67,7 +68,7 @@ It also implements several components of [OpenID Connect](https://openid.net/con
67
68
  * `oidc_frontchannel_logout` - [Frontchannel Logout](https://gitlab.com/os85/rodauth-oauth/-/wikis/Frontchannel-Logout);
68
69
  * `oidc_backchannel_logout` - [Backchannel Logout](https://gitlab.com/os85/rodauth-oauth/-/wikis/Backchannel-Logout);
69
70
 
70
- This gem supports also rails (through [rodauth-rails]((https://github.com/janko/rodauth-rails))).
71
+ This gem supports also rails (via [rodauth-rails]((https://github.com/janko/rodauth-rails)), which also dictates the versioning policy).
71
72
 
72
73
 
73
74
  ## Installation
@@ -0,0 +1,9 @@
1
+ ### 1.6.3
2
+
3
+ #### Improvements
4
+
5
+ * all routes can now be used via rodauth `internal_request` feature.
6
+
7
+ #### Bugfixes
8
+
9
+ * `oauth_application_management` feature: fixed "new oauth application" link to account for for prefix usage.
@@ -0,0 +1,9 @@
1
+ ### 1.6.4
2
+
3
+ #### Bugfixes
4
+
5
+ * on `/userinfo` request, enforce existence of oauth grant before proceeding with the userinfo requests.
6
+
7
+ #### Chore
8
+
9
+ * linting + tweaks to example scripts.
@@ -33,6 +33,10 @@ module Rodauth
33
33
  :oauth_grants_resource_owner_columns
34
34
  )
35
35
 
36
+ OAUTH_ACCESS_TYPES = %w[offline online].freeze
37
+
38
+ OAUTH_APPROVAL_PROMPTS = %w[force auto].freeze
39
+
36
40
  # /authorize
37
41
  auth_server_route(:authorize) do |r|
38
42
  require_authorizable_account
@@ -106,22 +110,18 @@ module Rodauth
106
110
  false
107
111
  end
108
112
 
109
- ACCESS_TYPES = %w[offline online].freeze
110
-
111
113
  def check_valid_access_type?
112
114
  return true unless use_oauth_access_type?
113
115
 
114
116
  access_type = param_or_nil("access_type")
115
- !access_type || ACCESS_TYPES.include?(access_type)
117
+ !access_type || OAUTH_ACCESS_TYPES.include?(access_type)
116
118
  end
117
119
 
118
- APPROVAL_PROMPTS = %w[force auto].freeze
119
-
120
120
  def check_valid_approval_prompt?
121
121
  return true unless use_oauth_access_type?
122
122
 
123
123
  approval_prompt = param_or_nil("approval_prompt")
124
- !approval_prompt || APPROVAL_PROMPTS.include?(approval_prompt)
124
+ !approval_prompt || OAUTH_APPROVAL_PROMPTS.include?(approval_prompt)
125
125
  end
126
126
 
127
127
  def resource_owner_params
@@ -142,7 +142,7 @@ module Rodauth
142
142
  oauth_grants_redirect_uri_column => redirect_uri,
143
143
  oauth_grants_scopes_column => scopes.join(oauth_scope_separator),
144
144
  oauth_grants_access_type_column => "online"
145
- ).count.zero?
145
+ ).none?
146
146
 
147
147
  # if there's a previous oauth grant for the params combo, it means that this user has approved before.
148
148
  request.env["REQUEST_METHOD"] = "POST"
@@ -462,14 +462,14 @@ module Rodauth
462
462
  end
463
463
 
464
464
  def generate_token(grant_params = {}, should_generate_refresh_token = true)
465
- if grant_params[oauth_grants_id_column] && (oauth_reuse_access_token &&
466
- (
467
- if oauth_grants_token_hash_column
468
- grant_params[oauth_grants_token_hash_column]
469
- else
470
- grant_params[oauth_grants_token_column]
471
- end
472
- ))
465
+ if grant_params[oauth_grants_id_column] && oauth_reuse_access_token &&
466
+ (
467
+ if oauth_grants_token_hash_column
468
+ grant_params[oauth_grants_token_hash_column]
469
+ else
470
+ grant_params[oauth_grants_token_column]
471
+ end
472
+ )
473
473
  return grant_params
474
474
  end
475
475
 
@@ -18,7 +18,7 @@ module Rodauth
18
18
  request.on(registration_client_uri_route) do
19
19
  # CLIENT REGISTRATION URI
20
20
  request.on(String) do |client_id|
21
- (token = (v = request.env["HTTP_AUTHORIZATION"]) && v[/\A *Bearer (.*)\Z/, 1])
21
+ token = (v = request.env["HTTP_AUTHORIZATION"]) && v[/\A *Bearer (.*)\Z/, 1]
22
22
 
23
23
  next unless token
24
24
 
@@ -266,14 +266,14 @@ module Rodauth
266
266
  end
267
267
 
268
268
  now = Time.now
269
- if verify_claims && (
270
- (!claims[:exp] || Time.at(claims[:exp]) < now) &&
271
- (claims[:nbf] && Time.at(claims[:nbf]) < now) &&
272
- (claims[:iat] && Time.at(claims[:iat]) < now) &&
273
- (verify_iss && claims[:iss] != oauth_jwt_issuer) &&
274
- (verify_aud && !verify_aud(claims[:aud], claims[:client_id])) &&
275
- (verify_jti && !verify_jti(claims[:jti], claims))
276
- )
269
+ if verify_claims &&
270
+ (!claims[:exp] || Time.at(claims[:exp]) < now) &&
271
+ claims[:nbf] && Time.at(claims[:nbf]) < now &&
272
+ claims[:iat] && Time.at(claims[:iat]) < now &&
273
+ verify_iss && claims[:iss] != oauth_jwt_issuer &&
274
+ verify_aud && !verify_aud(claims[:aud], claims[:client_id]) &&
275
+ verify_jti && !verify_jti(claims[:jti], claims)
276
+
277
277
  return
278
278
  end
279
279
 
@@ -347,7 +347,6 @@ module Rodauth
347
347
  def jwt_encode(payload,
348
348
  signing_algorithm: oauth_jwt_keys.keys.first,
349
349
  headers: {}, **)
350
-
351
350
  key = oauth_jwt_keys[signing_algorithm] || _jwt_key
352
351
  key = key.first if key.is_a?(Array)
353
352
 
@@ -475,7 +474,6 @@ module Rodauth
475
474
  jwe_key: oauth_jwt_jwe_keys[[jws_encryption_algorithm, jws_encryption_method]] || oauth_jwt_jwe_keys.values.first,
476
475
  **args
477
476
  )
478
-
479
477
  token = if jwks && jwks.any? { |k| k[:use] == "enc" }
480
478
  JWE.__rodauth_oauth_decrypt_from_jwks(token, jwks, alg: jws_encryption_algorithm, enc: jws_encryption_method)
481
479
  elsif jwe_key
@@ -99,7 +99,7 @@ module Rodauth
99
99
  private
100
100
 
101
101
  def require_oauth_application_for_introspect
102
- (token = (v = request.env["HTTP_AUTHORIZATION"]) && v[/\A *Bearer (.*)\Z/, 1])
102
+ token = (v = request.env["HTTP_AUTHORIZATION"]) && v[/\A *Bearer (.*)\Z/, 1]
103
103
 
104
104
  return require_oauth_application unless token
105
105
 
@@ -144,7 +144,9 @@ module Rodauth
144
144
  **resource_owner_params_from_jwt_claims(claims)
145
145
  ).first
146
146
 
147
- claims_locales = oauth_grant[oauth_grants_claims_locales_column] if oauth_grant
147
+ throw_json_response_error(oauth_authorization_required_error_status, "invalid_token") unless oauth_grant
148
+
149
+ claims_locales = oauth_grant[oauth_grants_claims_locales_column]
148
150
 
149
151
  if (claims = oauth_grant[oauth_grants_claims_column])
150
152
  claims = JSON.parse(claims)
@@ -317,9 +319,8 @@ module Rodauth
317
319
  # MUST ignore the offline_access request unless the Client
318
320
  # is using a response_type value that would result in an
319
321
  # Authorization Code
320
- if sc && sc.include?("offline_access") && !(param_or_nil("prompt") == "consent" && (
321
- (response_type = param_or_nil("response_type")) && response_type.split(" ").include?("code")
322
- ))
322
+ if sc && sc.include?("offline_access") && !(param_or_nil("prompt") == "consent" &&
323
+ (response_type = param_or_nil("response_type")) && response_type.split(" ").include?("code"))
323
324
  sc.delete("offline_access")
324
325
 
325
326
  request.params["scope"] = sc.join(" ")
@@ -792,9 +793,7 @@ module Rodauth
792
793
  # Metadata
793
794
 
794
795
  def openid_configuration_body(path = nil)
795
- metadata = oauth_server_metadata_body(path).select do |k, _|
796
- VALID_METADATA_KEYS.include?(k)
797
- end
796
+ metadata = oauth_server_metadata_body(path).slice(*VALID_METADATA_KEYS)
798
797
 
799
798
  scope_claims = oauth_application_scopes.each_with_object([]) do |scope, claims|
800
799
  oidc, param = scope.split(".", 2)
@@ -873,7 +872,7 @@ module Rodauth
873
872
  return unless digest
874
873
 
875
874
  hash = digest.digest(hash)
876
- hash = hash[0...hash.size / 2]
875
+ hash = hash[0...(hash.size / 2)]
877
876
  Base64.urlsafe_encode64(hash).tr("=", "")
878
877
  end
879
878
  end
@@ -132,8 +132,8 @@ module Rodauth
132
132
  end
133
133
  end
134
134
 
135
- if features.include?(:oidc_rp_initiated_logout) && (defined?(oauth_applications_post_logout_redirect_uris_column) &&
136
- (value = @oauth_application_params[oauth_applications_post_logout_redirect_uris_column]))
135
+ if features.include?(:oidc_rp_initiated_logout) && defined?(oauth_applications_post_logout_redirect_uris_column) &&
136
+ (value = @oauth_application_params[oauth_applications_post_logout_redirect_uris_column])
137
137
  if value.is_a?(Array)
138
138
  @oauth_application_params[oauth_applications_post_logout_redirect_uris_column] = value.each do |redirect_uri|
139
139
  unless check_valid_uri?(redirect_uri)
@@ -23,7 +23,7 @@ module Rodauth
23
23
  catch_error do
24
24
  validate_oidc_logout_params
25
25
 
26
- claims = oauth_application = nil
26
+ claims = nil
27
27
 
28
28
  if (id_token_hint = param_or_nil("id_token_hint"))
29
29
  #
@@ -81,7 +81,7 @@ module Rodauth
81
81
  end
82
82
 
83
83
  def __insert_or_do_nothing_and_return__(dataset, pkey, unique_columns, params)
84
- find_params = params.select { |key, _| unique_columns.include?(key) }
84
+ find_params = params.slice(*unique_columns)
85
85
  dataset.where(find_params).first || __insert_and_return__(dataset, pkey, params)
86
86
  end
87
87
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rodauth
4
4
  module OAuth
5
- VERSION = "1.6.2"
5
+ VERSION = "1.6.4"
6
6
  end
7
7
  end
data/lib/rodauth/oauth.rb CHANGED
@@ -6,8 +6,8 @@ require "rodauth/oauth/version"
6
6
  module Rodauth
7
7
  module OAuth
8
8
  module FeatureExtensions
9
- def auth_server_route(*args, &blk)
10
- routes = route(*args, &blk)
9
+ def auth_server_route(name, *args, &blk)
10
+ routes = route(name, *args, &blk)
11
11
 
12
12
  handle_meth = routes.last
13
13
 
@@ -19,6 +19,9 @@ module Rodauth
19
19
 
20
20
  alias_method :"#{handle_meth}_not_for_auth_server", handle_meth
21
21
  alias_method handle_meth, :"#{handle_meth}_for_auth_server"
22
+
23
+ # make all requests usable via internal_request feature
24
+ internal_request_method name
22
25
  end
23
26
 
24
27
  # override
@@ -1,5 +1,5 @@
1
1
  <div id="oauth-applications">
2
- <a class="btn btn-outline-primary" href="/oauth-applications/new">#{rodauth.new_oauth_application_page_title}</a>
2
+ <a class="btn btn-outline-primary" href="#{rodauth.oauth_applications_path}/new">#{rodauth.new_oauth_application_page_title}</a>
3
3
  #{
4
4
  if @oauth_applications.count.zero?
5
5
  "<p>#{rodauth.oauth_no_applications_text}</p>"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: base64
@@ -44,10 +43,10 @@ email:
44
43
  executables: []
45
44
  extensions: []
46
45
  extra_rdoc_files:
46
+ - CHANGELOG.md
47
47
  - LICENSE.txt
48
- - README.md
49
48
  - MIGRATION-GUIDE-v1.md
50
- - CHANGELOG.md
49
+ - README.md
51
50
  - doc/release_notes/0_0_1.md
52
51
  - doc/release_notes/0_0_2.md
53
52
  - doc/release_notes/0_0_3.md
@@ -91,6 +90,8 @@ extra_rdoc_files:
91
90
  - doc/release_notes/1_6_0.md
92
91
  - doc/release_notes/1_6_1.md
93
92
  - doc/release_notes/1_6_2.md
93
+ - doc/release_notes/1_6_3.md
94
+ - doc/release_notes/1_6_4.md
94
95
  files:
95
96
  - CHANGELOG.md
96
97
  - LICENSE.txt
@@ -139,6 +140,8 @@ files:
139
140
  - doc/release_notes/1_6_0.md
140
141
  - doc/release_notes/1_6_1.md
141
142
  - doc/release_notes/1_6_2.md
143
+ - doc/release_notes/1_6_3.md
144
+ - doc/release_notes/1_6_4.md
142
145
  - lib/generators/rodauth/oauth/install_generator.rb
143
146
  - lib/generators/rodauth/oauth/templates/app/models/oauth_application.rb
144
147
  - lib/generators/rodauth/oauth/templates/app/models/oauth_grant.rb
@@ -225,7 +228,6 @@ metadata:
225
228
  source_code_uri: https://gitlab.com/os85/rodauth-oauth
226
229
  changelog_uri: https://gitlab.com/os85/rodauth-oauth/-/blob/master/CHANGELOG.md
227
230
  rubygems_mfa_required: 'true'
228
- post_install_message:
229
231
  rdoc_options: []
230
232
  require_paths:
231
233
  - lib
@@ -240,8 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
242
  - !ruby/object:Gem::Version
241
243
  version: '0'
242
244
  requirements: []
243
- rubygems_version: 3.5.3
244
- signing_key:
245
+ rubygems_version: 3.6.9
245
246
  specification_version: 4
246
247
  summary: Implementation of the OAuth 2.0 protocol on top of rodauth.
247
248
  test_files: []