omniauth_oidc 1.1.0 → 1.2.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/CHANGELOG.md +9 -0
- data/README.md +30 -3
- data/lib/omniauth/oidc/version.rb +1 -1
- data/lib/omniauth/strategies/oidc/redirect_uri.rb +59 -0
- data/lib/omniauth/strategies/oidc/request.rb +6 -2
- data/lib/omniauth/strategies/oidc.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 559ac46903a09985d800496480384fbc44b41a6c202523f239d75d6418e5d974
|
|
4
|
+
data.tar.gz: 6b488ff0fe44435cf6aa5f50a8ab55a39ec3a524fe55fd25eb6517c9c01408f3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f402f1244f5bb63082a52967e2d6c3baf19afaa9f7f4d0a7bc28da2888b53c3c40e37babdbbb935f5b1d30953f7bd85d91c2d0e0fc4efe2b141e16a3223af74c
|
|
7
|
+
data.tar.gz: a48e0845a7df3dd2f0dd6118390e3a4778c44b9320f80c87755dcf6f975e7652d3add44d0a4f0ef84ac9fcb82e5a52966af395e6ed292974c41edc7693d7e419
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
## [Released]
|
|
2
2
|
|
|
3
|
+
## [1.2.0] - 2026-11-28
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **`redirect_uri` option**: Overrides the callback URL sent to the provider in the authorization and token requests, which otherwise defaults to `<request base url>/auth/<name>/callback`. Useful behind proxies that change the host or scheme, or when the registered callback URL differs from the request host. The value must be an absolute `http` or `https` URL without a fragment; anything else fails the login with the `configuration_error` key. A warning is logged when its path does not match the strategy's `callback_path`, because OmniAuth would then not handle the provider's redirect.
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- **Authorization parameters are no longer sent twice**: OmniAuth stores `extra_authorize_params` with string keys, so a configured parameter that the strategy also sets (such as `prompt` or `redirect_uri`) was added a second time instead of replacing the strategy's value. Configured parameters now replace it. Parameters listed in `allow_authorize_params` as strings could likewise add a second `state`, `nonce` or other built-in parameter from the request; they can now only add parameters the strategy and `extra_authorize_params` do not set.
|
|
10
|
+
- **`redirect_uri` in `extra_authorize_params` is ignored**: It was sent alongside the gem's own value, and the token request still used the gem's value. A warning now points to the `redirect_uri` option.
|
|
11
|
+
|
|
3
12
|
## [1.1.0] - 2026-10-14
|
|
4
13
|
|
|
5
14
|
### Security
|
data/README.md
CHANGED
|
@@ -95,7 +95,7 @@ end
|
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
Ensure to replace identifier, secret, configuration endpoint URL and others with credentials received from your OIDC provider.
|
|
98
|
-
|
|
98
|
+
By default the gem builds the `redirect_uri` dynamically from the request. You can override it with the `redirect_uri` option. For details please see section Routes.
|
|
99
99
|
|
|
100
100
|
### Redirecting for Authentication
|
|
101
101
|
|
|
@@ -161,12 +161,38 @@ The `omniauth.auth` hash includes:
|
|
|
161
161
|
|
|
162
162
|
### Routes
|
|
163
163
|
|
|
164
|
-
The gem uses dynamic routes when making requests to the OIDC provider endpoints, so called `redirect_uri` which
|
|
165
|
-
|
|
164
|
+
The gem uses dynamic routes when making requests to the OIDC provider endpoints, so called `redirect_uri` which by
|
|
165
|
+
default follows the naming pattern of `https://your_app.com/auth/<simple_provider>/callback`,
|
|
166
166
|
where `<simple_provider>` is the provider name defined within the configuration of the `omniauth.rb` initializer.
|
|
167
167
|
This represents the `redirect_uri` that will be passed with the authorization request to your OIDC provider and that
|
|
168
168
|
has to be registered with your OIDC provider as permitted `redirect_uri`.
|
|
169
169
|
|
|
170
|
+
If the URL your OIDC provider must redirect to differs from the one built from the request (for example, behind a
|
|
171
|
+
proxy or load balancer that changes the host or scheme, or when one callback URL is registered for several hosts), set
|
|
172
|
+
the `redirect_uri` option. The same value is sent in the authorization request and in the token request:
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
provider :oidc, {
|
|
176
|
+
name: :simple_provider,
|
|
177
|
+
redirect_uri: "https://your_app.com/auth/simple_provider/callback",
|
|
178
|
+
client_options: { ... }
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Keep the following in mind when setting `redirect_uri`:
|
|
183
|
+
|
|
184
|
+
- It must be an absolute `http` or `https` URL without a fragment. Any other value fails the login with the
|
|
185
|
+
`configuration_error` key.
|
|
186
|
+
- Its path must match the strategy's `callback_path` (by default `/auth/<name>/callback`). OmniAuth only handles the
|
|
187
|
+
provider's redirect on that path, so if they differ the redirect reaches your app without being authenticated. The gem
|
|
188
|
+
logs a warning when they do not match. Set `callback_path` to the same path if you change it.
|
|
189
|
+
- The request phase stores the `state`, nonce and PKCE verifier in the session. If `redirect_uri` points to a different
|
|
190
|
+
host than the one the login started on, the browser must send the same session cookie there. Otherwise the callback
|
|
191
|
+
fails with `csrf_detected` or `token_error`. Scope the session cookie to a shared parent domain (for example
|
|
192
|
+
`domain: ".your_app.com"`) when one callback URL serves several hosts.
|
|
193
|
+
- If you previously set `redirect_uri` in `extra_authorize_params` as a workaround, move it to this option. A
|
|
194
|
+
`redirect_uri` in `extra_authorize_params` is now ignored, and the gem logs a warning.
|
|
195
|
+
|
|
170
196
|
Dynamic routes are used to process responses and perform intermediary steps by the middleware, e.g. request phase,
|
|
171
197
|
token verification. While you can define and use same routes within your Rails app, it is highly recommended to modify
|
|
172
198
|
your `routes.rb` to perform a dynamic redirect to another controller method so this does not cause any conflicts with
|
|
@@ -342,6 +368,7 @@ You can customize the OIDC strategy further by adding additional configuration o
|
|
|
342
368
|
| prompt | Specifies whether the OIDC authorization server prompts the end user for reauthentication and consent | no | `nil` | `:none`, `:login`, `:consent` or `:select_account` |
|
|
343
369
|
| send_nonce | Include a nonce in the authorization request and require it in the ID token. Always on for `response_type: 'id_token'` | no | `true` | `true` or `false` |
|
|
344
370
|
| send_scope_to_token_endpoint | Should the scope parameter be sent to the authorization token endpoint | no | `true` | `true` or `false` |
|
|
371
|
+
| redirect_uri | Callback URL sent to the OIDC provider in the authorization and token requests. Must be an absolute URL registered with the provider | no | `<request base url>/auth/<name>/callback` | `"https://your_app.com/auth/simple_provider/callback"` |
|
|
345
372
|
| post_logout_redirect_uri | Logout redirect uri to use per the [session management draft](https://openid.net/specs/openid-connect-session-1_0.html) | no | `nil` | `"https://your_app.com/logout/callback"` |
|
|
346
373
|
| uid_field | **Deprecated**, removed in 2.0.0. Has never had an effect: the uid is always the `sub` claim | no | `"sub"` | Remove from configuration |
|
|
347
374
|
| extra_authorize_params | Hash of extra fixed parameters that will be merged to the authorization request | no | `{}` | `{"tenant" => "common"}` |
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OmniAuth
|
|
4
|
+
module Strategies
|
|
5
|
+
class Oidc
|
|
6
|
+
# The callback URL sent to the provider. The request and callback phases both read it from here,
|
|
7
|
+
# so the authorization request and the token exchange always send the same value (RFC 6749 4.1.3).
|
|
8
|
+
module RedirectUri
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def redirect_uri
|
|
12
|
+
configured_redirect_uri || "#{request.base_url}/auth/#{name}/callback"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# The redirect_uri option, or nil when it is not set.
|
|
16
|
+
# Raises ConfigurationError unless it is an absolute http(s) URL without a fragment (RFC 6749 3.1.2).
|
|
17
|
+
def configured_redirect_uri
|
|
18
|
+
value = options.redirect_uri
|
|
19
|
+
return if value.nil?
|
|
20
|
+
|
|
21
|
+
uri = parse_redirect_uri(value)
|
|
22
|
+
return value if uri.is_a?(URI::HTTP) && !uri.host.to_s.empty? && uri.fragment.nil?
|
|
23
|
+
|
|
24
|
+
raise OmniauthOidc::ConfigurationError,
|
|
25
|
+
"redirect_uri must be an absolute http(s) URL without a fragment, got #{value.inspect}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def parse_redirect_uri(value)
|
|
29
|
+
URI.parse(value.to_s)
|
|
30
|
+
rescue URI::InvalidURIError
|
|
31
|
+
raise OmniauthOidc::ConfigurationError, "redirect_uri is not a valid URL: #{value.inspect}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# OmniAuth only handles the provider's redirect on callback_path. A redirect_uri with any other path
|
|
35
|
+
# reaches the host app unauthenticated, unless a proxy rewrites it.
|
|
36
|
+
def warn_redirect_uri_path_mismatch
|
|
37
|
+
value = configured_redirect_uri
|
|
38
|
+
# A callable callback_path matches requests itself, so there is no single path to compare with
|
|
39
|
+
return if value.nil? || options.callback_path.respond_to?(:call)
|
|
40
|
+
|
|
41
|
+
path = URI.parse(value).path
|
|
42
|
+
return if path.casecmp?(callback_path)
|
|
43
|
+
|
|
44
|
+
OmniauthOidc::Logging.warn("The redirect_uri path #{path} does not match the callback path " \
|
|
45
|
+
"#{callback_path} of the #{name} provider, so OmniAuth will not handle " \
|
|
46
|
+
"the provider's redirect. Set callback_path to #{path}.")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The README used to say redirect_uri could not be configured, so it may have been set here instead.
|
|
50
|
+
def warn_redirect_uri_in_extra_authorize_params
|
|
51
|
+
return unless options.extra_authorize_params.to_h.keys.any? { |key| key.to_s == "redirect_uri" }
|
|
52
|
+
|
|
53
|
+
OmniauthOidc::Logging.warn("redirect_uri in extra_authorize_params is ignored by the #{name} provider. " \
|
|
54
|
+
"Use the redirect_uri option instead.")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -8,6 +8,7 @@ module OmniAuth
|
|
|
8
8
|
def request_phase
|
|
9
9
|
OmniauthOidc::Logging.instrument("request_phase.start", provider: name) do
|
|
10
10
|
set_client_options_for_request_phase
|
|
11
|
+
warn_redirect_uri_path_mismatch
|
|
11
12
|
redirect authorize_uri
|
|
12
13
|
end
|
|
13
14
|
rescue OmniauthOidc::ConfigurationError => e
|
|
@@ -18,9 +19,12 @@ module OmniAuth
|
|
|
18
19
|
def authorize_uri # rubocop:disable Metrics/AbcSize
|
|
19
20
|
opts = request_options
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
# OmniAuth stores option hashes with string keys. Keys are symbolized so that no param is sent twice:
|
|
23
|
+
# a configured param replaces the strategy's own value, and a request param never replaces either.
|
|
24
|
+
options.extra_authorize_params.each { |key, value| opts[key.to_sym] = value }
|
|
22
25
|
|
|
23
26
|
options.allow_authorize_params.each do |key|
|
|
27
|
+
key = key.to_sym
|
|
24
28
|
opts[key] = request.params[key.to_s] unless opts.key?(key)
|
|
25
29
|
end
|
|
26
30
|
|
|
@@ -31,7 +35,7 @@ module OmniAuth
|
|
|
31
35
|
session[session_key("pkce.verifier")] = verifier
|
|
32
36
|
end
|
|
33
37
|
|
|
34
|
-
#
|
|
38
|
+
# Set last so neither extra_authorize_params nor request params can change it
|
|
35
39
|
opts[:redirect_uri] = redirect_uri
|
|
36
40
|
opts[:extra_params] = opts.compact
|
|
37
41
|
|
|
@@ -14,6 +14,7 @@ require "openssl"
|
|
|
14
14
|
require_relative "oidc/request"
|
|
15
15
|
require_relative "oidc/callback"
|
|
16
16
|
require_relative "oidc/verify"
|
|
17
|
+
require_relative "oidc/redirect_uri"
|
|
17
18
|
|
|
18
19
|
module OmniAuth
|
|
19
20
|
module Strategies
|
|
@@ -23,6 +24,7 @@ module OmniAuth
|
|
|
23
24
|
include Request
|
|
24
25
|
include Callback
|
|
25
26
|
include Verify
|
|
27
|
+
include RedirectUri
|
|
26
28
|
|
|
27
29
|
extend Forwardable
|
|
28
30
|
|
|
@@ -48,6 +50,7 @@ module OmniAuth
|
|
|
48
50
|
jwks_uri: nil, # optional
|
|
49
51
|
end_session_endpoint: nil) # optional
|
|
50
52
|
|
|
53
|
+
option :redirect_uri
|
|
51
54
|
option :issuer
|
|
52
55
|
option :client_signing_alg
|
|
53
56
|
option :jwt_secret_base64
|
|
@@ -94,6 +97,7 @@ module OmniAuth
|
|
|
94
97
|
def initialize(app, *args, &block)
|
|
95
98
|
super
|
|
96
99
|
warn_uid_field_deprecation
|
|
100
|
+
warn_redirect_uri_in_extra_authorize_params
|
|
97
101
|
end
|
|
98
102
|
|
|
99
103
|
# Always the subject claim: the only identifier OIDC guarantees to be stable and unique per issuer
|
|
@@ -256,10 +260,6 @@ module OmniAuth
|
|
|
256
260
|
super
|
|
257
261
|
end
|
|
258
262
|
|
|
259
|
-
def redirect_uri
|
|
260
|
-
"#{request.base_url}/auth/#{name}/callback"
|
|
261
|
-
end
|
|
262
|
-
|
|
263
263
|
def encoded_post_logout_redirect_uri
|
|
264
264
|
return unless options.post_logout_redirect_uri
|
|
265
265
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omniauth_oidc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Suleyman Musayev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jwt
|
|
@@ -95,6 +95,7 @@ files:
|
|
|
95
95
|
- lib/omniauth/oidc/version.rb
|
|
96
96
|
- lib/omniauth/strategies/oidc.rb
|
|
97
97
|
- lib/omniauth/strategies/oidc/callback.rb
|
|
98
|
+
- lib/omniauth/strategies/oidc/redirect_uri.rb
|
|
98
99
|
- lib/omniauth/strategies/oidc/request.rb
|
|
99
100
|
- lib/omniauth/strategies/oidc/verify.rb
|
|
100
101
|
- lib/omniauth_oidc.rb
|