omniauth_openid_federation 2.1.0 → 2.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 +22 -15
- data/README.md +36 -11
- data/app/controllers/omniauth_openid_federation/federation_controller.rb +21 -55
- data/config/polyrun_coverage.yml +1 -1
- data/config/routes.rb +3 -0
- data/examples/README_INTEGRATION_TESTING.md +3 -3
- data/examples/README_MOCK_OP.md +11 -11
- data/examples/integration_test_flow.rb +5 -5
- data/examples/jobs/README.md +11 -11
- data/examples/mock_op_server.rb +1 -1
- data/examples/relying_party_key_rotation.rb.example +29 -0
- data/lib/omniauth_openid_federation/client_keys.rb +38 -0
- data/lib/omniauth_openid_federation/constants.rb +8 -0
- data/lib/omniauth_openid_federation/controller.rb +34 -0
- data/lib/omniauth_openid_federation/engine.rb +7 -6
- data/lib/omniauth_openid_federation/jwks/normalizer.rb +8 -2
- data/lib/omniauth_openid_federation/jwt_response_decoder.rb +9 -4
- data/lib/omniauth_openid_federation/key_resolver.rb +36 -0
- data/lib/omniauth_openid_federation/oidc_client.rb +17 -2
- data/lib/omniauth_openid_federation/rack_endpoint.rb +5 -5
- data/lib/omniauth_openid_federation/rails.rb +25 -0
- data/lib/omniauth_openid_federation/relying_party_key_store.rb +110 -0
- data/lib/omniauth_openid_federation/strategy/authorization_request.rb +5 -3
- data/lib/omniauth_openid_federation/strategy/client_construction.rb +14 -7
- data/lib/omniauth_openid_federation/strategy/id_token_decoding.rb +7 -4
- data/lib/omniauth_openid_federation/strategy/userinfo_decoding.rb +7 -4
- data/lib/omniauth_openid_federation/strategy.rb +4 -0
- data/lib/omniauth_openid_federation/tasks/callback_processor.rb +7 -7
- data/lib/omniauth_openid_federation/tasks/local_endpoint_tester.rb +3 -3
- data/lib/omniauth_openid_federation/utils.rb +21 -14
- data/lib/omniauth_openid_federation/validators.rb +8 -14
- data/lib/omniauth_openid_federation/version.rb +1 -1
- data/lib/omniauth_openid_federation.rb +5 -1
- data/lib/tasks/omniauth_openid_federation.rake +96 -96
- metadata +9 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 06eb00cceeca266e7eb952398a2b89ce9fb6c01e537e4f3bcf39d0c3b4e2d633
|
|
4
|
+
data.tar.gz: 378844a5fb14eae224fad9a7d1fc2d6fc5a9689d6635645d625d83c3f35dc30f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c069f152a683f084e002aac4ba0c15f61875a7fb1a3586a2d93747275fbcefef2a67a370f9562afff46e4f9b94f6de0ac419381b7d4b994b046525962165bc6
|
|
7
|
+
data.tar.gz: d533de4e933a346235f4c948e62bf66e8b05c4218528e5956974407ca5485ac0f5e332f47681f3e85942fe0df244f94053f81bb5bfaa3bc324063769bbdfc857
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.2.0 (2026-11-11)
|
|
6
|
+
|
|
7
|
+
- Fix Rack well-known entity configuration responses to use `application/entity-statement+jwt`
|
|
8
|
+
- Add `require "omniauth_openid_federation/rails"` for `require: false` hosts, injectable federation controller base, and signed JWKS `.jwt` / `.jose` path aliases
|
|
9
|
+
- Add reloadable relying-party signing and encryption keys (callables), `reset_client!`, and optional file / ENV / cache key stores
|
|
10
|
+
- Stop depending on ActiveSupport `Hash#stringify_keys` when normalizing JWKS
|
|
11
|
+
|
|
5
12
|
## 2.1.0 (2026-10-29)
|
|
6
13
|
|
|
7
14
|
- BREAKING: Require Ruby `>= 3.4` (gemspec); drop Rails 6 and TruffleRuby appraisal targets from the tested matrix
|
|
@@ -16,7 +23,7 @@
|
|
|
16
23
|
- Fix `client_entity_statement_url` so `load_client_entity_statement` fetches from the URL
|
|
17
24
|
- Fix `Utils.validate_file_path!` allowed-directory checks to require a path-separator boundary
|
|
18
25
|
- Stop streaming HTTP responses at the configured byte limit and close oversized responses before buffering the remaining body
|
|
19
|
-
- Add `rfcs/` starter pack: process (RFC 0001), positioning (RFC 0002), and Standards Track design RFCs 0003
|
|
26
|
+
- Add `rfcs/` starter pack: process (RFC 0001), positioning (RFC 0002), and Standards Track design RFCs 0003-0006 for strategy, trust chain, token verification, and federation endpoint
|
|
20
27
|
- Document Ruby `>= 3.4` in README requirements
|
|
21
28
|
|
|
22
29
|
## 2.0.0 (2026-07-06)
|
|
@@ -90,24 +97,24 @@
|
|
|
90
97
|
- Enhanced instrumentation: All blocking exceptions automatically reported through instrumentation system, including OmniAuth middleware errors (like AuthenticityTokenProtection)
|
|
91
98
|
- CSRF protection instrumentation: New authenticity_error event type for reporting OmniAuth CSRF failures
|
|
92
99
|
- Comprehensive error reporting: Override fail! method in strategy to catch and instrument all authentication failures
|
|
93
|
-
- CSRF protection documentation: Added
|
|
100
|
+
- CSRF protection documentation: Added Step 7 in README for request and callback CSRF configuration
|
|
94
101
|
- CSRF configuration examples: Added complete examples in examples/config/initializers/devise.rb.example and examples/app/controllers/users/omniauth_callbacks_controller.rb.example
|
|
95
102
|
- Deprecation warnings: Added runtime deprecation warnings for json_jwt method and ftn_spname option to guide users to recommended alternatives
|
|
96
103
|
- Code cleanup: Removed deprecated load_signing_key method (unused, returned nil)
|
|
97
104
|
- Updated deprecation notices: Fixed deprecation notices to reference correct replacement methods (request_object_params instead of non-existent provider_extension_params)
|
|
98
|
-
- Renamed option: `allow_authorize_params`
|
|
105
|
+
- Renamed option: `allow_authorize_params` -> `request_object_params` for clarity (uses RFC 9101 terminology, clearly indicates params go into JWT request object)
|
|
99
106
|
|
|
100
107
|
## 1.0.0 (2025-11-26)
|
|
101
108
|
|
|
102
|
-
- Initial public release
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
- ID token encryption and decryption
|
|
106
|
-
-
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
- Works with
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
109
|
+
- Initial public release
|
|
110
|
+
- OpenID Federation 1.0 entity statement validation and trust chain resolution
|
|
111
|
+
- Signed authorization requests
|
|
112
|
+
- ID token encryption and decryption
|
|
113
|
+
- Client authentication without shared secrets (`private_key_jwt`)
|
|
114
|
+
- Provider key rotation handling
|
|
115
|
+
- Rate limiting, path traversal protection, and error sanitization
|
|
116
|
+
- Thread-safe configuration and bounded retry delays
|
|
117
|
+
- Works with OpenID Federation providers that accept custom extension parameters
|
|
118
|
+
- Compatible with Rails, Sinatra, Rack, and other Rack-compatible frameworks
|
|
119
|
+
- Rake tasks for entity statements and key management
|
|
120
|
+
- RBS type signatures for IDE support
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/omniauth_openid_federation) [](https://github.com/amkisko/omniauth_openid_federation.rb/actions/workflows/test.yml) [](https://app.codecov.io/github/amkisko/omniauth_openid_federation.rb) [](https://sonarcloud.io/project/overview?id=amkisko_omniauth_openid_federation.rb)
|
|
4
4
|
|
|
5
|
-
OmniAuth strategy for OpenID Federation providers
|
|
5
|
+
OmniAuth strategy for OpenID Federation providers. Supports signed request objects, ID token encryption, and OpenID Federation 1.0 entity statements.
|
|
6
6
|
|
|
7
7
|
Design changes go through `rfcs/` (RFC 0001).
|
|
8
8
|
|
|
@@ -13,21 +13,43 @@ Design changes go through `rfcs/` (RFC 0001).
|
|
|
13
13
|
gem "omniauth_openid_federation"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
For `require: false` (feature-flagged load), require the Rails entrypoint before routes:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
# Gemfile
|
|
20
|
+
gem "omniauth_openid_federation", require: false
|
|
21
|
+
|
|
22
|
+
# config/application.rb or an early initializer
|
|
23
|
+
require "omniauth_openid_federation/rails"
|
|
24
|
+
# Optional for API hosts without a HTML ApplicationController:
|
|
25
|
+
# OmniauthOpenidFederation.base_controller = "ActionController::API"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
API hosts that must avoid Action Controller filters can mount Rack only:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
# config.ru or middleware
|
|
32
|
+
require "omniauth_openid_federation/rack"
|
|
33
|
+
map "/.well-known" do
|
|
34
|
+
run OmniauthOpenidFederation::RackEndpoint.new
|
|
35
|
+
end
|
|
36
|
+
```
|
|
37
|
+
|
|
16
38
|
```bash
|
|
17
39
|
bundle install
|
|
18
40
|
```
|
|
19
41
|
|
|
20
42
|
## Features
|
|
21
43
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
44
|
+
- Signed request objects (RFC 9101): RS256 signing of authorization requests
|
|
45
|
+
- Optional request object encryption: RSA-OAEP when the provider requires it
|
|
46
|
+
- ID token encryption and decryption: RSA-OAEP and A128CBC-HS256
|
|
47
|
+
- OpenID Federation 1.0: entity statements and federation metadata
|
|
48
|
+
- Federation endpoint: publish entity statements at `/.well-known/openid-federation`
|
|
49
|
+
- Automatic key provisioning: extract or generate signing and encryption keys
|
|
50
|
+
- Separate signing and encryption keys when the host needs them
|
|
51
|
+
- Client assertion (`private_key_jwt`) for client authentication
|
|
52
|
+
- Input validation, rate limiting, and related request hardening
|
|
31
53
|
|
|
32
54
|
## Quick Start
|
|
33
55
|
|
|
@@ -437,11 +459,14 @@ rake openid_federation:test_authentication_flow[
|
|
|
437
459
|
|
|
438
460
|
- `client_options.identifier` - Client ID from provider
|
|
439
461
|
- `client_options.redirect_uri` - Callback URL
|
|
440
|
-
- `client_options.private_key` - RSA private key for signing
|
|
462
|
+
- `client_options.private_key` or `signing_key` - RSA private key for signing (OpenSSL key, PEM string, or callable resolved on each use)
|
|
441
463
|
- `entity_statement_path` - Path to cached entity statement file
|
|
442
464
|
|
|
443
465
|
### Optional
|
|
444
466
|
|
|
467
|
+
- `signing_key` / `client_options.signing_key` - RP signing key (preferred over a shared `private_key`)
|
|
468
|
+
- `encryption_key` / `client_options.encryption_key` - RP decryption key for encrypted ID tokens / userinfo
|
|
469
|
+
- `signing_key_source` / `decryption_key_source` - `:local` or `:federation` (federation JWKS must include private `d` to sign or decrypt locally)
|
|
445
470
|
- `entity_statement_url` - URL to fetch entity statement (auto-fetches if provided)
|
|
446
471
|
- `entity_statement_fingerprint` - Fingerprint for verification
|
|
447
472
|
- `client_entity_statement_url` - Client entity statement URL (for automatic registration)
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
# Federation Controller for serving entity statements and JWKS
|
|
2
2
|
# @see https://openid.net/specs/openid-federation-1_0.html OpenID Federation 1.0 Specification
|
|
3
3
|
#
|
|
4
|
-
# Serves
|
|
4
|
+
# Serves endpoints:
|
|
5
5
|
# - /.well-known/openid-federation - Entity statement JWT
|
|
6
6
|
# - /.well-known/openid-federation/fetch - Fetch endpoint for Subordinate Statements
|
|
7
7
|
# - /.well-known/jwks.json - Standard JWKS (JSON)
|
|
8
|
-
# - /.well-known/signed-jwks.json - Signed JWKS (JWT)
|
|
8
|
+
# - /.well-known/signed-jwks.json|.jwt|.jose - Signed JWKS (JWT)
|
|
9
9
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
10
|
+
# Parent class is OmniauthOpenidFederation.base_controller (default ApplicationController,
|
|
11
|
+
# or ActionController::API when ApplicationController is absent). Set before load:
|
|
12
|
+
# OmniauthOpenidFederation.base_controller = "ActionController::API"
|
|
12
13
|
require "omniauth_openid_federation/cache_adapter"
|
|
14
|
+
require "omniauth_openid_federation/controller"
|
|
15
|
+
require "omniauth_openid_federation/constants"
|
|
13
16
|
|
|
14
17
|
module OmniauthOpenidFederation
|
|
15
|
-
class FederationController <
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
class FederationController < OmniauthOpenidFederation.base_controller_class
|
|
19
|
+
if respond_to?(:skip_before_action)
|
|
20
|
+
skip_before_action :verify_authorized, raise: false
|
|
21
|
+
skip_after_action :verify_policy_scoped, raise: false if respond_to?(:skip_after_action)
|
|
22
|
+
end
|
|
23
|
+
|
|
21
24
|
def show
|
|
22
25
|
entity_statement = OmniauthOpenidFederation::FederationEndpoint.generate_entity_statement
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
response.headers["Content-Type"] = "application/entity-statement+jwt"
|
|
27
|
-
response.headers["Cache-Control"] = "public, max-age=3600" # Cache for 1 hour
|
|
27
|
+
response.headers["Content-Type"] = Constants::CONTENT_TYPE_ENTITY_STATEMENT_JWT
|
|
28
|
+
response.headers["Cache-Control"] = "public, max-age=3600"
|
|
28
29
|
|
|
29
30
|
render plain: entity_statement
|
|
30
31
|
rescue OmniauthOpenidFederation::ConfigurationError => e
|
|
@@ -35,14 +36,7 @@ module OmniauthOpenidFederation
|
|
|
35
36
|
render plain: "Internal server error", status: :internal_server_error
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
# Serve fetch endpoint (for Subordinate Statements)
|
|
39
|
-
#
|
|
40
|
-
# GET /.well-known/openid-federation/fetch?sub=<subject_entity_id>
|
|
41
|
-
#
|
|
42
|
-
# Returns a Subordinate Statement JWT for the specified subject entity.
|
|
43
|
-
# Per OpenID Federation 1.0 Section 6.1.
|
|
44
39
|
def fetch
|
|
45
|
-
# Extract 'sub' query parameter (required per spec)
|
|
46
40
|
subject_entity_id = params[:sub]
|
|
47
41
|
|
|
48
42
|
unless subject_entity_id
|
|
@@ -50,10 +44,7 @@ module OmniauthOpenidFederation
|
|
|
50
44
|
return
|
|
51
45
|
end
|
|
52
46
|
|
|
53
|
-
# Security: Validate entity identifier per OpenID Federation 1.0 spec
|
|
54
|
-
# Entity identifiers must be valid HTTP/HTTPS URIs
|
|
55
47
|
begin
|
|
56
|
-
# Validate and get trimmed value
|
|
57
48
|
subject_entity_id = OmniauthOpenidFederation::Validators.validate_entity_identifier!(subject_entity_id, max_length: 2048)
|
|
58
49
|
rescue SecurityError => e
|
|
59
50
|
render json: {error: "invalid_request", error_description: "Invalid subject entity ID: #{e.message}"}, status: :bad_request
|
|
@@ -63,14 +54,12 @@ module OmniauthOpenidFederation
|
|
|
63
54
|
return
|
|
64
55
|
end
|
|
65
56
|
|
|
66
|
-
# Validate that subject is not the issuer (invalid request per spec)
|
|
67
57
|
config = OmniauthOpenidFederation::FederationEndpoint.configuration
|
|
68
58
|
if subject_entity_id == config.issuer
|
|
69
59
|
render json: {error: "invalid_request", error_description: "Subject cannot be the issuer"}, status: :bad_request
|
|
70
60
|
return
|
|
71
61
|
end
|
|
72
62
|
|
|
73
|
-
# Get Subordinate Statement
|
|
74
63
|
subordinate_statement = OmniauthOpenidFederation::FederationEndpoint.get_subordinate_statement(subject_entity_id)
|
|
75
64
|
|
|
76
65
|
unless subordinate_statement
|
|
@@ -78,9 +67,8 @@ module OmniauthOpenidFederation
|
|
|
78
67
|
return
|
|
79
68
|
end
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
response.headers["
|
|
83
|
-
response.headers["Cache-Control"] = "public, max-age=3600" # Cache for 1 hour
|
|
70
|
+
response.headers["Content-Type"] = Constants::CONTENT_TYPE_ENTITY_STATEMENT_JWT
|
|
71
|
+
response.headers["Cache-Control"] = "public, max-age=3600"
|
|
84
72
|
|
|
85
73
|
render plain: subordinate_statement
|
|
86
74
|
rescue OmniauthOpenidFederation::ConfigurationError => e
|
|
@@ -91,20 +79,10 @@ module OmniauthOpenidFederation
|
|
|
91
79
|
render json: {error: "Internal server error"}, status: :internal_server_error
|
|
92
80
|
end
|
|
93
81
|
|
|
94
|
-
# Serve standard JWKS
|
|
95
|
-
#
|
|
96
|
-
# GET /.well-known/jwks.json
|
|
97
|
-
#
|
|
98
|
-
# Returns the current JWKS in JSON format.
|
|
99
|
-
# Uses config.current_jwks or config.current_jwks_proc if configured,
|
|
100
|
-
# otherwise falls back to entity statement JWKS.
|
|
101
82
|
def jwks
|
|
102
83
|
config = OmniauthOpenidFederation::FederationEndpoint.configuration
|
|
103
|
-
|
|
104
|
-
# Get current JWKS (may differ from entity statement JWKS)
|
|
105
84
|
jwks_to_serve = OmniauthOpenidFederation::FederationEndpoint.current_jwks
|
|
106
85
|
|
|
107
|
-
# Apply server-side caching if available
|
|
108
86
|
cache_key = OmniauthOpenidFederation::Cache.key_for_served_jwks(config.issuer)
|
|
109
87
|
cache_ttl = config.jwks_cache_ttl || 3600
|
|
110
88
|
|
|
@@ -116,8 +94,8 @@ module OmniauthOpenidFederation
|
|
|
116
94
|
jwks_to_serve.to_json
|
|
117
95
|
end
|
|
118
96
|
|
|
119
|
-
response.headers["Content-Type"] =
|
|
120
|
-
response.headers["Cache-Control"] = "public, max-age=3600"
|
|
97
|
+
response.headers["Content-Type"] = Constants::CONTENT_TYPE_JSON
|
|
98
|
+
response.headers["Cache-Control"] = "public, max-age=3600"
|
|
121
99
|
|
|
122
100
|
render json: JSON.parse(jwks_json)
|
|
123
101
|
rescue OmniauthOpenidFederation::ConfigurationError => e
|
|
@@ -128,22 +106,10 @@ module OmniauthOpenidFederation
|
|
|
128
106
|
render json: {error: "Internal server error"}, status: :internal_server_error
|
|
129
107
|
end
|
|
130
108
|
|
|
131
|
-
# Serve signed JWKS
|
|
132
|
-
#
|
|
133
|
-
# GET /.well-known/signed-jwks.json
|
|
134
|
-
#
|
|
135
|
-
# Returns the current JWKS wrapped in a JWT, signed with entity statement key.
|
|
136
|
-
# Note: Despite the .json extension (per OpenID Federation spec), this endpoint returns
|
|
137
|
-
# application/jwt (a JWT), not plain JSON. The Content-Type header correctly indicates application/jwt.
|
|
138
|
-
# Uses config.signed_jwks_payload or config.signed_jwks_payload_proc if configured,
|
|
139
|
-
# otherwise falls back to entity statement JWKS.
|
|
140
109
|
def signed_jwks
|
|
141
110
|
config = OmniauthOpenidFederation::FederationEndpoint.configuration
|
|
142
|
-
|
|
143
|
-
# Generate signed JWKS JWT
|
|
144
111
|
signed_jwks_jwt = OmniauthOpenidFederation::FederationEndpoint.generate_signed_jwks
|
|
145
112
|
|
|
146
|
-
# Apply server-side caching if available
|
|
147
113
|
cache_key = OmniauthOpenidFederation::Cache.key_for_served_signed_jwks(config.issuer)
|
|
148
114
|
cache_ttl = config.jwks_cache_ttl || 3600
|
|
149
115
|
|
|
@@ -155,8 +121,8 @@ module OmniauthOpenidFederation
|
|
|
155
121
|
signed_jwks_jwt
|
|
156
122
|
end
|
|
157
123
|
|
|
158
|
-
response.headers["Content-Type"] =
|
|
159
|
-
response.headers["Cache-Control"] = "public, max-age=3600"
|
|
124
|
+
response.headers["Content-Type"] = Constants::CONTENT_TYPE_JWT
|
|
125
|
+
response.headers["Cache-Control"] = "public, max-age=3600"
|
|
160
126
|
|
|
161
127
|
render plain: cached_jwt
|
|
162
128
|
rescue OmniauthOpenidFederation::ConfigurationError => e
|
data/config/polyrun_coverage.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Polyrun::Coverage::Rails
|
|
1
|
+
# Polyrun::Coverage::Rails - loaded from spec/spec_helper via Polyrun::Coverage::Rails.start!
|
|
2
2
|
# (must run before application code; keep coverage config here, not in initializers)
|
|
3
3
|
#
|
|
4
4
|
# Do not set track_files here: with track_files, Polyrun merges the full Coverage.result blob
|
data/config/routes.rb
CHANGED
|
@@ -20,6 +20,9 @@ unless @_omniauth_openid_federation_routes_loaded
|
|
|
20
20
|
|
|
21
21
|
# Signed JWKS endpoint (OpenID Federation requirement)
|
|
22
22
|
get "/.well-known/signed-jwks.json", to: "omniauth_openid_federation/federation#signed_jwks", as: :openid_federation_signed_jwks
|
|
23
|
+
# Compatibility aliases for registrars that expect .jwt / .jose paths
|
|
24
|
+
get "/.well-known/signed-jwks.jwt", to: "omniauth_openid_federation/federation#signed_jwks", as: :openid_federation_signed_jwks_jwt
|
|
25
|
+
get "/.well-known/signed-jwks.jose", to: "omniauth_openid_federation/federation#signed_jwks", as: :openid_federation_signed_jwks_jose
|
|
23
26
|
end
|
|
24
27
|
rescue NameError, LoadError
|
|
25
28
|
# Rails not available or not fully initialized - routes will be loaded when Engine initializes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# OpenID Federation Integration Testing
|
|
2
2
|
|
|
3
|
-
This directory contains
|
|
3
|
+
This directory contains mock servers and integration tests for the OpenID Federation flow.
|
|
4
4
|
|
|
5
5
|
## Architecture
|
|
6
6
|
|
|
@@ -354,7 +354,7 @@ redirect_uris:
|
|
|
354
354
|
|
|
355
355
|
## Security Testing
|
|
356
356
|
|
|
357
|
-
The mock servers support
|
|
357
|
+
The mock servers support security testing:
|
|
358
358
|
|
|
359
359
|
- **Algorithm Confusion**: Test rejection of non-RS256 algorithms
|
|
360
360
|
- **Key Confusion**: Test rejection of wrong keys
|
|
@@ -398,5 +398,5 @@ The mock servers support comprehensive security testing:
|
|
|
398
398
|
2. **Performance Testing**: Add load testing scenarios
|
|
399
399
|
3. **Security Testing**: Add fuzzing and penetration tests
|
|
400
400
|
4. **Trust Mark Testing**: Add trust mark validation
|
|
401
|
-
5.
|
|
401
|
+
5. Metadata Policy Testing: Add policy merging tests
|
|
402
402
|
|
data/examples/README_MOCK_OP.md
CHANGED
|
@@ -4,12 +4,12 @@ A standalone Rack/Sinatra application for testing OpenID Federation flows.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
7
|
+
- Entity Configuration endpoint (`/.well-known/openid-federation`)
|
|
8
|
+
- Fetch Endpoint (`/.well-known/openid-federation/fetch`) for Subordinate Statements
|
|
9
|
+
- Authorization Endpoint (`/auth`) with trust chain resolution
|
|
10
|
+
- Token Endpoint (`/token`) with ID Token signing
|
|
11
|
+
- JWKS endpoints (standard and signed)
|
|
12
|
+
- UserInfo endpoint (mock)
|
|
13
13
|
|
|
14
14
|
## Quick Start
|
|
15
15
|
|
|
@@ -203,11 +203,11 @@ config.omniauth :openid_federation,
|
|
|
203
203
|
|
|
204
204
|
This is a **mock server for testing only**:
|
|
205
205
|
|
|
206
|
-
-
|
|
207
|
-
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
-
|
|
206
|
+
- WARNING: No real user authentication (always returns mock user)
|
|
207
|
+
- WARNING: Authorization codes stored in memory (lost on restart)
|
|
208
|
+
- WARNING: No database persistence
|
|
209
|
+
- WARNING: No production security hardening
|
|
210
|
+
- WARNING: ID Tokens contain mock user data
|
|
211
211
|
|
|
212
212
|
## Production Considerations
|
|
213
213
|
|
|
@@ -331,7 +331,7 @@ class IntegrationTestFlow
|
|
|
331
331
|
|
|
332
332
|
if response.code == "200"
|
|
333
333
|
elapsed = (OmniauthOpenidFederation::TimeHelpers.now - start_time).round(1)
|
|
334
|
-
puts "
|
|
334
|
+
puts " OK: #{url} is ready (#{elapsed}s)"
|
|
335
335
|
ready = true
|
|
336
336
|
end
|
|
337
337
|
rescue
|
|
@@ -351,7 +351,7 @@ class IntegrationTestFlow
|
|
|
351
351
|
|
|
352
352
|
unless ready
|
|
353
353
|
elapsed = (OmniauthOpenidFederation::TimeHelpers.now - start_time).round(1)
|
|
354
|
-
puts "\n
|
|
354
|
+
puts "\n Error: #{server_name} server at #{url} did not become ready in time (#{elapsed}s)"
|
|
355
355
|
err_log = File.join(@tmp_dir, "#{server_name.downcase}_server_error.log")
|
|
356
356
|
log_file = File.join(@tmp_dir, "#{server_name.downcase}_server.log")
|
|
357
357
|
|
|
@@ -378,7 +378,7 @@ class IntegrationTestFlow
|
|
|
378
378
|
end
|
|
379
379
|
|
|
380
380
|
def test(name)
|
|
381
|
-
print "
|
|
381
|
+
print " OK: #{name}... "
|
|
382
382
|
begin
|
|
383
383
|
result = yield
|
|
384
384
|
if result
|
|
@@ -389,7 +389,7 @@ class IntegrationTestFlow
|
|
|
389
389
|
@test_results << {name: name, status: :fail}
|
|
390
390
|
end
|
|
391
391
|
rescue => e
|
|
392
|
-
puts "
|
|
392
|
+
puts "Error: #{e.message}"
|
|
393
393
|
@test_results << {name: name, status: :error, error: e.message}
|
|
394
394
|
end
|
|
395
395
|
end
|
|
@@ -1260,7 +1260,7 @@ class IntegrationTestFlow
|
|
|
1260
1260
|
end
|
|
1261
1261
|
|
|
1262
1262
|
puts ""
|
|
1263
|
-
puts (passed == @test_results.length) ? "
|
|
1263
|
+
puts (passed == @test_results.length) ? "OK: All tests passed!" : "Error: Some tests failed."
|
|
1264
1264
|
|
|
1265
1265
|
passed == @test_results.length
|
|
1266
1266
|
end
|
data/examples/jobs/README.md
CHANGED
|
@@ -107,21 +107,21 @@ bin/rails runner 'FederationCacheRefreshJob.perform_now'
|
|
|
107
107
|
## When to Use Each Job
|
|
108
108
|
|
|
109
109
|
### Use FederationFilesGenerationJob when:
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
110
|
+
- You want files on disk for backup/recovery
|
|
111
|
+
- You want to serve from files instead of generating on-demand
|
|
112
|
+
- You need files for external tools or scripts
|
|
113
|
+
- You want to version control generated files (not recommended for production)
|
|
114
114
|
|
|
115
115
|
### Use FederationCacheRefreshJob when:
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
116
|
+
- You only need in-memory caching (Rails.cache)
|
|
117
|
+
- You want to refresh caches without generating files
|
|
118
|
+
- You want faster cache refresh cycles
|
|
119
|
+
- You don't need files on disk
|
|
120
120
|
|
|
121
121
|
### Use Both when:
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
122
|
+
- You want both file generation and cache refresh
|
|
123
|
+
- You want redundancy (files + cache)
|
|
124
|
+
- You have different refresh cycles for files vs cache
|
|
125
125
|
|
|
126
126
|
## Key Rotation Workflow
|
|
127
127
|
|
data/examples/mock_op_server.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# Enhanced Mock OpenID Provider (OP) Server for OpenID Federation Testing
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Standalone Webrick server that acts as a mock OP server
|
|
7
7
|
# for testing OpenID Federation flows. It supports:
|
|
8
8
|
# - Entity Configuration endpoint (/.well-known/openid-federation)
|
|
9
9
|
# - Fetch Endpoint (/.well-known/openid-federation/fetch)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Example: rotate RP signing/encryption keys and refresh served JWKS without restart.
|
|
2
|
+
#
|
|
3
|
+
# store = OmniauthOpenidFederation::RelyingPartyKeyStore::CacheStore.new(
|
|
4
|
+
# cache_key_prefix: "openid_federation/rp_keys"
|
|
5
|
+
# )
|
|
6
|
+
# record = store.rotate
|
|
7
|
+
#
|
|
8
|
+
# OmniauthOpenidFederation::FederationEndpoint.configure do |config|
|
|
9
|
+
# config.signing_key = record.signing_key
|
|
10
|
+
# config.encryption_key = record.encryption_key
|
|
11
|
+
# config.private_key = record.signing_key
|
|
12
|
+
# config.current_jwks_proc = -> {
|
|
13
|
+
# {
|
|
14
|
+
# keys: [
|
|
15
|
+
# OmniauthOpenidFederation::Utils.rsa_key_to_jwk(record.signing_key, use: "sig"),
|
|
16
|
+
# OmniauthOpenidFederation::Utils.rsa_key_to_jwk(record.encryption_key, use: "enc")
|
|
17
|
+
# ]
|
|
18
|
+
# }
|
|
19
|
+
# }
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# Strategy client_options can use callables:
|
|
23
|
+
#
|
|
24
|
+
# client_options: {
|
|
25
|
+
# signing_key: -> { store.load.signing_key },
|
|
26
|
+
# encryption_key: -> { store.load.encryption_key }
|
|
27
|
+
# }
|
|
28
|
+
#
|
|
29
|
+
# Invalidate served JWKS cache keys after rotation when CacheAdapter is enabled.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "key_resolver"
|
|
4
|
+
require_relative "validators"
|
|
5
|
+
|
|
6
|
+
module OmniauthOpenidFederation
|
|
7
|
+
# Resolves signing and encryption keys from client_options / strategy options.
|
|
8
|
+
module ClientKeys
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def signing_key(normalized_client_options, strategy_options = {})
|
|
12
|
+
KeyResolver.resolve(
|
|
13
|
+
pick(normalized_client_options, :signing_key) ||
|
|
14
|
+
strategy_options[:signing_key] ||
|
|
15
|
+
pick(normalized_client_options, :private_key)
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def encryption_key(normalized_client_options, strategy_options = {})
|
|
20
|
+
KeyResolver.resolve(
|
|
21
|
+
pick(normalized_client_options, :encryption_key) ||
|
|
22
|
+
strategy_options[:encryption_key] ||
|
|
23
|
+
pick(normalized_client_options, :private_key)
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def validate_signing_key!(normalized_client_options, strategy_options = {})
|
|
28
|
+
key = signing_key(normalized_client_options, strategy_options)
|
|
29
|
+
Validators.validate_private_key!(key)
|
|
30
|
+
key
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def pick(hash, key)
|
|
34
|
+
hash[key] || hash[key.to_s]
|
|
35
|
+
end
|
|
36
|
+
private_class_method :pick
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -20,5 +20,13 @@ module OmniauthOpenidFederation
|
|
|
20
20
|
|
|
21
21
|
# Maximum HTTP response body size for federation/JWKS fetches (1 MiB)
|
|
22
22
|
MAX_HTTP_RESPONSE_BODY_BYTES = 1_048_576
|
|
23
|
+
|
|
24
|
+
# OpenID Federation 1.0 entity statement / entity configuration responses (section 8.1, section 9.2)
|
|
25
|
+
CONTENT_TYPE_ENTITY_STATEMENT_JWT = "application/entity-statement+jwt"
|
|
26
|
+
|
|
27
|
+
# Signed JWKS and generic JWT responses
|
|
28
|
+
CONTENT_TYPE_JWT = "application/jwt"
|
|
29
|
+
|
|
30
|
+
CONTENT_TYPE_JSON = "application/json"
|
|
23
31
|
end
|
|
24
32
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OmniauthOpenidFederation
|
|
4
|
+
class << self
|
|
5
|
+
attr_writer :base_controller
|
|
6
|
+
|
|
7
|
+
# Host controller class or name for FederationController.
|
|
8
|
+
# Set before the controller loads (for example in an initializer before routes).
|
|
9
|
+
#
|
|
10
|
+
# @return [Class, String]
|
|
11
|
+
def base_controller
|
|
12
|
+
@base_controller || default_base_controller
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [Class]
|
|
16
|
+
def base_controller_class
|
|
17
|
+
value = base_controller
|
|
18
|
+
return value if value.is_a?(Class)
|
|
19
|
+
|
|
20
|
+
value.to_s.constantize
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def default_base_controller
|
|
24
|
+
return "ApplicationController" if defined?(::ApplicationController)
|
|
25
|
+
return "ActionController::API" if defined?(::ActionController::API)
|
|
26
|
+
|
|
27
|
+
"ActionController::Base"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def reset_base_controller!
|
|
31
|
+
@base_controller = nil
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -6,12 +6,13 @@ module OmniauthOpenidFederation
|
|
|
6
6
|
class Engine < ::Rails::Engine
|
|
7
7
|
# Don't isolate namespace because we need routes at specific well-known paths
|
|
8
8
|
# (/.well-known/openid-federation) rather than under a mount point
|
|
9
|
-
# isolate_namespace OmniauthOpenidFederation
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
initializer "omniauth_openid_federation.append_controller_paths", before: :set_load_path do |app|
|
|
11
|
+
controllers = root.join("app", "controllers")
|
|
12
|
+
next unless controllers.exist?
|
|
13
|
+
|
|
14
|
+
app.config.autoload_paths << controllers.to_s
|
|
15
|
+
app.config.eager_load_paths << controllers.to_s
|
|
16
|
+
end
|
|
16
17
|
end
|
|
17
18
|
end
|
|
@@ -35,7 +35,7 @@ module OmniauthOpenidFederation
|
|
|
35
35
|
{
|
|
36
36
|
"keys" => Array(keys).map do |jwk|
|
|
37
37
|
if jwk.is_a?(Hash)
|
|
38
|
-
jwk
|
|
38
|
+
stringify_hash_keys(jwk)
|
|
39
39
|
else
|
|
40
40
|
JSON.parse(jwk.to_json)
|
|
41
41
|
end
|
|
@@ -43,7 +43,13 @@ module OmniauthOpenidFederation
|
|
|
43
43
|
}
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
def self.stringify_hash_keys(hash)
|
|
47
|
+
hash.each_with_object({}) do |(key, value), result|
|
|
48
|
+
result[key.to_s] = value.is_a?(Hash) ? stringify_hash_keys(value) : value
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private_class_method :normalize_keys_array, :stringify_hash_keys
|
|
47
53
|
end
|
|
48
54
|
end
|
|
49
55
|
end
|