omniauth_openid_federation 2.2.1 → 2.3.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 +6 -0
- data/README.md +3 -1
- data/lib/omniauth_openid_federation/strategy.rb +14 -5
- data/lib/omniauth_openid_federation/tasks.rb +8 -0
- data/lib/omniauth_openid_federation/version.rb +1 -1
- data/lib/omniauth_openid_federation.rb +0 -1
- data/lib/tasks/omniauth_openid_federation.rake +7 -7
- data/sig/strategy.rbs +1 -0
- metadata +2 -20
- data/examples/README_INTEGRATION_TESTING.md +0 -402
- data/examples/README_MOCK_OP.md +0 -243
- data/examples/app/controllers/users/omniauth_callbacks_controller.rb.example +0 -37
- data/examples/app/jobs/jwks_rotation_job.rb.example +0 -60
- data/examples/app/models/user.rb.example +0 -39
- data/examples/config/initializers/devise.rb.example +0 -120
- data/examples/config/initializers/federation_endpoint.rb.example +0 -206
- data/examples/config/mock_op.yml.example +0 -83
- data/examples/config/open_id_connect_config.rb.example +0 -207
- data/examples/config/routes.rb.example +0 -16
- data/examples/db/migrate/add_omniauth_to_users.rb.example +0 -16
- data/examples/integration_test_flow.rb +0 -1336
- data/examples/jobs/README.md +0 -194
- data/examples/jobs/federation_cache_refresh_job.rb.example +0 -78
- data/examples/jobs/federation_files_generation_job.rb.example +0 -88
- data/examples/mock_op_server.rb +0 -774
- data/examples/mock_rp_server.rb +0 -435
- data/examples/relying_party_key_rotation.rb.example +0 -34
- data/examples/standalone_multiple_endpoints_example.rb +0 -494
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e528379f1e7988b36918b82102bfea958a60b6187a5a0821babcc955b52545b
|
|
4
|
+
data.tar.gz: 88bb1fcc5ffcb138c1f5c085e42cb2f3b90b3533aad91e499ac3d4cfa0b75c05
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47f2594e9d8308f36e2738fc423066c30485e7b77c3bab633bd57aa1acd9f43bf34804aef061b02ce025d1daae5e729fd6bdcae8f2c459b0cb30f1a04fded2a8
|
|
7
|
+
data.tar.gz: 965a9799d1d25388ba0241b6460f1cf6d42b9562b13f22031fcc88191ce8447bd3a80edc5e290d5c4b18b1e14f12bac661ac62c798c95bc18c50176a658d2818
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.3.0 (2026-11-18)
|
|
6
|
+
|
|
7
|
+
- Expose verified ID token claims on `auth.extra.id_token_claims` (including `acr` and other signed claims) separately from the UserInfo-merged `raw_info`
|
|
8
|
+
- Stop shipping `examples/` inside the gem package; use the repository tree for examples
|
|
9
|
+
- Load rake/CLI helpers via `require "omniauth_openid_federation/tasks"` instead of the main gem entry
|
|
10
|
+
|
|
5
11
|
## 2.2.1 (2026-11-11)
|
|
6
12
|
|
|
7
13
|
- Fix README Rails routes example: keep Engine mount inside one `routes.draw` (a nested second draw cleared the mount and 404'd well-known paths)
|
data/README.md
CHANGED
|
@@ -240,6 +240,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|
|
240
240
|
|
|
241
241
|
def openid_federation
|
|
242
242
|
auth = request.env["omniauth.auth"]
|
|
243
|
+
# auth.extra.raw_info is ID token claims merged with UserInfo (iss/sub/aud/exp/iat stay from the ID token).
|
|
244
|
+
# auth.extra.id_token_claims is the verified ID token payload only (use this for acr and other signed claims).
|
|
243
245
|
user = User.find_or_create_from_omniauth(auth)
|
|
244
246
|
|
|
245
247
|
if user&.persisted?
|
|
@@ -512,7 +514,7 @@ rake openid_federation:test_authentication_flow[
|
|
|
512
514
|
|
|
513
515
|
## Example Files
|
|
514
516
|
|
|
515
|
-
|
|
517
|
+
Examples live in the GitHub repository `examples/` tree (not shipped inside the gem package):
|
|
516
518
|
- `examples/standalone_multiple_endpoints_example.rb` - Standalone Sinatra app with multiple auth endpoints and entrance point-based redirects
|
|
517
519
|
- `examples/config/initializers/devise.rb.example` - Devise integration example (Rails)
|
|
518
520
|
- `examples/config/initializers/omniauth_openid_federation.rb.example` - Federation endpoint configuration
|
|
@@ -148,10 +148,18 @@ module OmniAuth
|
|
|
148
148
|
|
|
149
149
|
extra do
|
|
150
150
|
{
|
|
151
|
-
raw_info: raw_info
|
|
151
|
+
raw_info: raw_info,
|
|
152
|
+
id_token_claims: id_token_claims
|
|
152
153
|
}
|
|
153
154
|
end
|
|
154
155
|
|
|
156
|
+
# Verified ID token claims after signature and claim validation.
|
|
157
|
+
# Distinct from raw_info, which may merge UserInfo over non-identity claims.
|
|
158
|
+
def id_token_claims
|
|
159
|
+
raw_info
|
|
160
|
+
@id_token_claims || {}
|
|
161
|
+
end
|
|
162
|
+
|
|
155
163
|
def raw_info
|
|
156
164
|
@raw_info ||= begin
|
|
157
165
|
# Use access token from callback_phase (already exchanged)
|
|
@@ -160,24 +168,25 @@ module OmniAuth
|
|
|
160
168
|
access_token ||= exchange_authorization_code(request.params["code"])
|
|
161
169
|
|
|
162
170
|
id_token = decode_id_token(access_token.id_token)
|
|
163
|
-
|
|
171
|
+
verified_claims = stringify_claim_keys(id_token.raw_attributes || {})
|
|
172
|
+
@id_token_claims = verified_claims.dup
|
|
164
173
|
|
|
165
174
|
if options.fetch_userinfo
|
|
166
175
|
begin
|
|
167
176
|
userinfo = access_token.userinfo!
|
|
168
177
|
userinfo_hash = decode_userinfo(userinfo)
|
|
169
|
-
merge_userinfo_with_id_token_claims(
|
|
178
|
+
merge_userinfo_with_id_token_claims(verified_claims, userinfo_hash)
|
|
170
179
|
rescue OmniauthOpenidFederation::ValidationError
|
|
171
180
|
raise
|
|
172
181
|
rescue => e
|
|
173
182
|
error_msg = "Failed to fetch or decode userinfo: #{e.class} - #{e.message}"
|
|
174
183
|
OmniauthOpenidFederation::Logger.error("[Strategy] #{error_msg}")
|
|
175
184
|
OmniauthOpenidFederation::Logger.warn("[Strategy] Falling back to ID token claims only")
|
|
176
|
-
|
|
185
|
+
verified_claims
|
|
177
186
|
end
|
|
178
187
|
else
|
|
179
188
|
OmniauthOpenidFederation::Logger.debug("[Strategy] Userinfo fetching disabled, using ID token claims only")
|
|
180
|
-
|
|
189
|
+
verified_claims
|
|
181
190
|
end
|
|
182
191
|
end
|
|
183
192
|
end
|
|
@@ -67,7 +67,6 @@ require_relative "omniauth_openid_federation/federation/metadata_policy_merger"
|
|
|
67
67
|
require_relative "omniauth_openid_federation/federation/signed_jwks"
|
|
68
68
|
require_relative "omniauth_openid_federation/federation_endpoint"
|
|
69
69
|
require_relative "omniauth_openid_federation/entity_statement_reader"
|
|
70
|
-
require_relative "omniauth_openid_federation/tasks_helper"
|
|
71
70
|
require_relative "omniauth_openid_federation/endpoint_resolver"
|
|
72
71
|
require_relative "omniauth_openid_federation/strategy"
|
|
73
72
|
require_relative "omniauth_openid_federation/access_token"
|
|
@@ -5,7 +5,7 @@ require_relative "../omniauth_openid_federation/time_helpers"
|
|
|
5
5
|
namespace :openid_federation do
|
|
6
6
|
desc "Fetch entity statement from OpenID Federation provider"
|
|
7
7
|
task :fetch_entity_statement, [:url, :fingerprint, :output_file] => :environment do |_t, args|
|
|
8
|
-
require "omniauth_openid_federation"
|
|
8
|
+
require "omniauth_openid_federation/tasks"
|
|
9
9
|
|
|
10
10
|
url = args[:url] || ENV["ENTITY_STATEMENT_URL"]
|
|
11
11
|
fingerprint = args[:fingerprint] || ENV["ENTITY_STATEMENT_FINGERPRINT"]
|
|
@@ -61,7 +61,7 @@ namespace :openid_federation do
|
|
|
61
61
|
|
|
62
62
|
desc "Validate existing entity statement file"
|
|
63
63
|
task :validate_entity_statement, [:file_path, :fingerprint] => :environment do |_t, args|
|
|
64
|
-
require "omniauth_openid_federation"
|
|
64
|
+
require "omniauth_openid_federation/tasks"
|
|
65
65
|
|
|
66
66
|
file_path = args[:file_path] || ENV["ENTITY_STATEMENT_PATH"] || "config/provider-entity-statement.jwt"
|
|
67
67
|
expected_fingerprint = args[:fingerprint] || ENV["ENTITY_STATEMENT_FINGERPRINT"]
|
|
@@ -103,7 +103,7 @@ namespace :openid_federation do
|
|
|
103
103
|
|
|
104
104
|
desc "Fetch JWKS from provider"
|
|
105
105
|
task :fetch_jwks, [:jwks_uri, :output_file] => :environment do |_t, args|
|
|
106
|
-
require "omniauth_openid_federation"
|
|
106
|
+
require "omniauth_openid_federation/tasks"
|
|
107
107
|
|
|
108
108
|
jwks_uri = args[:jwks_uri] || ENV["JWKS_URI"]
|
|
109
109
|
output_file = args[:output_file] || ENV["JWKS_OUTPUT"] || "config/provider-jwks.json"
|
|
@@ -143,7 +143,7 @@ namespace :openid_federation do
|
|
|
143
143
|
|
|
144
144
|
desc "Parse entity statement and display endpoints"
|
|
145
145
|
task :parse_entity_statement, [:file_path] => :environment do |_t, args|
|
|
146
|
-
require "omniauth_openid_federation"
|
|
146
|
+
require "omniauth_openid_federation/tasks"
|
|
147
147
|
require "json"
|
|
148
148
|
|
|
149
149
|
file_path = args[:file_path] || ENV["ENTITY_STATEMENT_PATH"] || "config/provider-entity-statement.jwt"
|
|
@@ -165,7 +165,7 @@ namespace :openid_federation do
|
|
|
165
165
|
|
|
166
166
|
desc "Generate client keys and prepare public JWKS for provider registration"
|
|
167
167
|
task :prepare_client_keys, [:key_type, :output_dir] => :environment do |_t, args|
|
|
168
|
-
require "omniauth_openid_federation"
|
|
168
|
+
require "omniauth_openid_federation/tasks"
|
|
169
169
|
require "json"
|
|
170
170
|
require "fileutils"
|
|
171
171
|
|
|
@@ -222,7 +222,7 @@ namespace :openid_federation do
|
|
|
222
222
|
|
|
223
223
|
desc "Test local entity statement endpoint and all linked endpoints"
|
|
224
224
|
task :test_local_endpoint, [:base_url] => :environment do |_t, args|
|
|
225
|
-
require "omniauth_openid_federation"
|
|
225
|
+
require "omniauth_openid_federation/tasks"
|
|
226
226
|
|
|
227
227
|
base_url = args[:base_url] || ENV["BASE_URL"] || "http://localhost:3000"
|
|
228
228
|
|
|
@@ -377,7 +377,7 @@ namespace :openid_federation do
|
|
|
377
377
|
|
|
378
378
|
desc "Test full OpenID Federation authentication flow with a real provider"
|
|
379
379
|
task :test_authentication_flow, [:login_page_url, :base_url, :provider_acr] => :environment do |_t, args|
|
|
380
|
-
require "omniauth_openid_federation"
|
|
380
|
+
require "omniauth_openid_federation/tasks"
|
|
381
381
|
require "cgi"
|
|
382
382
|
require "base64"
|
|
383
383
|
require "openssl"
|
data/sig/strategy.rbs
CHANGED
|
@@ -8,6 +8,7 @@ module OmniAuth
|
|
|
8
8
|
def auth_hash: () -> OmniAuth::AuthHash
|
|
9
9
|
def authorize_uri: () -> String
|
|
10
10
|
def raw_info: () -> Hash[String, untyped]
|
|
11
|
+
def id_token_claims: () -> Hash[String, untyped]
|
|
11
12
|
def client_jwk_signing_key: () -> untyped
|
|
12
13
|
def options: () -> untyped
|
|
13
14
|
def exchange_authorization_code: (String authorization_code) -> OmniauthOpenidFederation::AccessToken
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omniauth_openid_federation
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -467,25 +467,6 @@ files:
|
|
|
467
467
|
- config/polyrun_coverage.yml
|
|
468
468
|
- config/polyrun_spec_quality.yml
|
|
469
469
|
- config/routes.rb
|
|
470
|
-
- examples/README_INTEGRATION_TESTING.md
|
|
471
|
-
- examples/README_MOCK_OP.md
|
|
472
|
-
- examples/app/controllers/users/omniauth_callbacks_controller.rb.example
|
|
473
|
-
- examples/app/jobs/jwks_rotation_job.rb.example
|
|
474
|
-
- examples/app/models/user.rb.example
|
|
475
|
-
- examples/config/initializers/devise.rb.example
|
|
476
|
-
- examples/config/initializers/federation_endpoint.rb.example
|
|
477
|
-
- examples/config/mock_op.yml.example
|
|
478
|
-
- examples/config/open_id_connect_config.rb.example
|
|
479
|
-
- examples/config/routes.rb.example
|
|
480
|
-
- examples/db/migrate/add_omniauth_to_users.rb.example
|
|
481
|
-
- examples/integration_test_flow.rb
|
|
482
|
-
- examples/jobs/README.md
|
|
483
|
-
- examples/jobs/federation_cache_refresh_job.rb.example
|
|
484
|
-
- examples/jobs/federation_files_generation_job.rb.example
|
|
485
|
-
- examples/mock_op_server.rb
|
|
486
|
-
- examples/mock_rp_server.rb
|
|
487
|
-
- examples/relying_party_key_rotation.rb.example
|
|
488
|
-
- examples/standalone_multiple_endpoints_example.rb
|
|
489
470
|
- lib/omniauth_openid_federation.rb
|
|
490
471
|
- lib/omniauth_openid_federation/access_token.rb
|
|
491
472
|
- lib/omniauth_openid_federation/cache.rb
|
|
@@ -545,6 +526,7 @@ files:
|
|
|
545
526
|
- lib/omniauth_openid_federation/strategy/provider_entity_statement.rb
|
|
546
527
|
- lib/omniauth_openid_federation/strategy/userinfo_decoding.rb
|
|
547
528
|
- lib/omniauth_openid_federation/string_helpers.rb
|
|
529
|
+
- lib/omniauth_openid_federation/tasks.rb
|
|
548
530
|
- lib/omniauth_openid_federation/tasks/authentication_flow_tester.rb
|
|
549
531
|
- lib/omniauth_openid_federation/tasks/callback_processor.rb
|
|
550
532
|
- lib/omniauth_openid_federation/tasks/client_keys_preparer.rb
|
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
# OpenID Federation Integration Testing
|
|
2
|
-
|
|
3
|
-
This directory contains mock servers and integration tests for the OpenID Federation flow.
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
|
-
The integration test setup consists of:
|
|
8
|
-
|
|
9
|
-
1. **Mock OP Server** (`mock_op_server.rb`) - Simulates an OpenID Provider
|
|
10
|
-
2. **Mock RP Server** (`mock_rp_server.rb`) - Simulates a Relying Party (Client)
|
|
11
|
-
3. **Integration Test Flow** (`integration_test_flow.rb`) - Automated tests for the complete flow
|
|
12
|
-
|
|
13
|
-
## Complete OpenID Federation Flow
|
|
14
|
-
|
|
15
|
-
### 1. Provider Exposes Entity Statement with JWKS
|
|
16
|
-
|
|
17
|
-
The OP server exposes its entity configuration at:
|
|
18
|
-
```
|
|
19
|
-
GET /.well-known/openid-federation
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Returns a signed JWT containing:
|
|
23
|
-
- Provider metadata (authorization_endpoint, token_endpoint, etc.)
|
|
24
|
-
- JWKS (public keys for signing/encryption)
|
|
25
|
-
- Authority hints (if subordinate to a Trust Anchor)
|
|
26
|
-
|
|
27
|
-
### 2. Client Exposes Entity Statement with JWKS
|
|
28
|
-
|
|
29
|
-
The RP server exposes its entity configuration at:
|
|
30
|
-
```
|
|
31
|
-
GET /.well-known/openid-federation
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Returns a signed JWT containing:
|
|
35
|
-
- RP metadata (redirect_uris, client_name, etc.)
|
|
36
|
-
- JWKS (public keys for signing request objects)
|
|
37
|
-
- Authority hints (if subordinate to a Trust Anchor)
|
|
38
|
-
|
|
39
|
-
### 3. Client Fetches Provider Statement with Keys
|
|
40
|
-
|
|
41
|
-
When the RP initiates login:
|
|
42
|
-
1. RP fetches OP's entity statement from `/.well-known/openid-federation`
|
|
43
|
-
2. RP validates the entity statement signature
|
|
44
|
-
3. RP extracts OP's JWKS for future token validation
|
|
45
|
-
4. RP extracts OP's metadata (endpoints, capabilities)
|
|
46
|
-
|
|
47
|
-
### 4. Client Sends Login Request
|
|
48
|
-
|
|
49
|
-
RP generates a signed request object (JWT) containing:
|
|
50
|
-
- `client_id`: RP's Entity ID
|
|
51
|
-
- `redirect_uri`: Callback URL
|
|
52
|
-
- `scope`: Requested scopes
|
|
53
|
-
- `state`: CSRF protection
|
|
54
|
-
- `nonce`: Replay protection
|
|
55
|
-
- `aud`: OP's Entity ID
|
|
56
|
-
|
|
57
|
-
The request object is:
|
|
58
|
-
- **Always signed** with RP's private key (RFC 9101 requirement)
|
|
59
|
-
- **Optionally encrypted** if OP requires encryption
|
|
60
|
-
|
|
61
|
-
RP redirects to OP's authorization endpoint:
|
|
62
|
-
```
|
|
63
|
-
GET /auth?request=<signed_jwt>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### 5. Provider Fetches Client Statement and Keys
|
|
67
|
-
|
|
68
|
-
When OP receives the authorization request:
|
|
69
|
-
1. OP extracts `client_id` from the request object
|
|
70
|
-
2. OP fetches RP's entity statement from `/.well-known/openid-federation`
|
|
71
|
-
3. OP validates RP's entity statement signature
|
|
72
|
-
4. OP extracts RP's JWKS from the entity statement
|
|
73
|
-
5. OP validates the request object signature using RP's public key
|
|
74
|
-
6. OP resolves RP's trust chain (if trust anchors configured)
|
|
75
|
-
7. OP applies metadata policies from trust chain
|
|
76
|
-
8. OP validates `redirect_uri` against RP's allowed redirect URIs
|
|
77
|
-
|
|
78
|
-
### 6. Exchange and Authenticated Login
|
|
79
|
-
|
|
80
|
-
After user authorization:
|
|
81
|
-
1. OP redirects back to RP with authorization code
|
|
82
|
-
2. RP exchanges code for tokens at OP's token endpoint
|
|
83
|
-
3. OP returns ID token (signed with OP's private key)
|
|
84
|
-
4. RP validates ID token signature using OP's JWKS
|
|
85
|
-
5. RP validates ID token claims (iss, aud, exp, nonce)
|
|
86
|
-
6. User is authenticated
|
|
87
|
-
|
|
88
|
-
## Error Scenarios Supported
|
|
89
|
-
|
|
90
|
-
The mock servers support error injection via `?error_mode=<mode>` parameter:
|
|
91
|
-
|
|
92
|
-
### Invalid Statement
|
|
93
|
-
```
|
|
94
|
-
GET /.well-known/openid-federation?error_mode=invalid_statement
|
|
95
|
-
```
|
|
96
|
-
Returns malformed JWT to test error handling.
|
|
97
|
-
|
|
98
|
-
### Wrong Keys
|
|
99
|
-
```
|
|
100
|
-
GET /.well-known/jwks.json?error_mode=wrong_keys
|
|
101
|
-
GET /.well-known/openid-federation?error_mode=wrong_keys
|
|
102
|
-
```
|
|
103
|
-
Returns JWKS with keys that don't match the signing key.
|
|
104
|
-
|
|
105
|
-
### Invalid Request
|
|
106
|
-
```
|
|
107
|
-
GET /auth?error_mode=invalid_request
|
|
108
|
-
```
|
|
109
|
-
Rejects request object validation to test error handling.
|
|
110
|
-
|
|
111
|
-
### Invalid Signature
|
|
112
|
-
```
|
|
113
|
-
GET /.well-known/signed-jwks.json?error_mode=invalid_signature
|
|
114
|
-
```
|
|
115
|
-
Returns signed JWKS with invalid signature.
|
|
116
|
-
|
|
117
|
-
### Expired Statement
|
|
118
|
-
```
|
|
119
|
-
GET /.well-known/openid-federation?error_mode=expired_statement
|
|
120
|
-
```
|
|
121
|
-
Returns expired entity statement to test expiration handling.
|
|
122
|
-
|
|
123
|
-
### Missing Metadata
|
|
124
|
-
```
|
|
125
|
-
GET /.well-known/openid-federation?error_mode=missing_metadata
|
|
126
|
-
```
|
|
127
|
-
Returns entity statement without metadata to test validation.
|
|
128
|
-
|
|
129
|
-
## Usage
|
|
130
|
-
|
|
131
|
-
### Quick Start (Automated - Recommended)
|
|
132
|
-
|
|
133
|
-
The integration test flow can automatically start servers, generate keys, and run all tests:
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
# Single command - fully automated
|
|
137
|
-
ruby examples/integration_test_flow.rb
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
This will:
|
|
141
|
-
1. Create temporary directories for keys and configs
|
|
142
|
-
2. Generate RSA keys for both OP and RP (using rake task logic)
|
|
143
|
-
3. Configure and start both servers automatically
|
|
144
|
-
4. Wait for servers to be ready
|
|
145
|
-
5. Run all integration tests
|
|
146
|
-
6. Clean up (kill servers, remove tmp dirs) on exit
|
|
147
|
-
|
|
148
|
-
CI runs the same flow on every push to `main` (see `.github/workflows/test.yml`, job `integration`).
|
|
149
|
-
Locally: `make integration-test` or `bundle exec ruby examples/integration_test_flow.rb` (exits non-zero on failure).
|
|
150
|
-
|
|
151
|
-
### Manual Start (For Debugging)
|
|
152
|
-
|
|
153
|
-
If you want to start servers manually for debugging:
|
|
154
|
-
|
|
155
|
-
**Terminal 1 - OP Server:**
|
|
156
|
-
```bash
|
|
157
|
-
ruby examples/mock_op_server.rb
|
|
158
|
-
# Server runs on http://localhost:9292
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
**Terminal 2 - RP Server:**
|
|
162
|
-
```bash
|
|
163
|
-
ruby examples/mock_rp_server.rb
|
|
164
|
-
# Server runs on http://localhost:9293
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
**Terminal 3 - Integration Tests:**
|
|
168
|
-
```bash
|
|
169
|
-
# Disable auto-start to use manually started servers
|
|
170
|
-
AUTO_START_SERVERS=false ruby examples/integration_test_flow.rb
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Environment Variables
|
|
174
|
-
|
|
175
|
-
The integration test flow supports the following environment variables:
|
|
176
|
-
|
|
177
|
-
```bash
|
|
178
|
-
# Server URLs
|
|
179
|
-
OP_URL=http://localhost:9292 # OP server URL
|
|
180
|
-
RP_URL=http://localhost:9293 # RP server URL
|
|
181
|
-
|
|
182
|
-
# Server Ports
|
|
183
|
-
OP_PORT=9292 # OP server port
|
|
184
|
-
RP_PORT=9293 # RP server port
|
|
185
|
-
|
|
186
|
-
# Entity IDs
|
|
187
|
-
OP_ENTITY_ID=https://op.example.com # OP entity identifier
|
|
188
|
-
RP_ENTITY_ID=https://rp.example.com # RP entity identifier
|
|
189
|
-
|
|
190
|
-
# Temporary Directory
|
|
191
|
-
TMP_DIR=tmp/integration_test # Directory for keys/configs (default: tmp/integration_test)
|
|
192
|
-
|
|
193
|
-
# Auto-start servers (true/false)
|
|
194
|
-
AUTO_START_SERVERS=true # Auto-start servers (default: true)
|
|
195
|
-
|
|
196
|
-
# Cleanup on exit (true/false)
|
|
197
|
-
CLEANUP_ON_EXIT=true # Clean up tmp dirs on exit (default: true)
|
|
198
|
-
|
|
199
|
-
# Key Type
|
|
200
|
-
KEY_TYPE=separate # 'single' or 'separate' (default: separate)
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
**Example with custom configuration:**
|
|
204
|
-
```bash
|
|
205
|
-
KEY_TYPE=separate \
|
|
206
|
-
TMP_DIR=/tmp/my_test \
|
|
207
|
-
ruby examples/integration_test_flow.rb
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
**Note**: By default, the integration test uses localhost URLs for complete isolation:
|
|
211
|
-
- No DNS resolution required
|
|
212
|
-
- No external network dependencies
|
|
213
|
-
- All communication happens on localhost
|
|
214
|
-
- Entity IDs default to `http://localhost:9292` (OP) and `http://localhost:9293` (RP)
|
|
215
|
-
|
|
216
|
-
This ensures the tests work in any environment without network configuration.
|
|
217
|
-
|
|
218
|
-
### Manual Testing
|
|
219
|
-
|
|
220
|
-
**1. Test Provider Entity Statement:**
|
|
221
|
-
```bash
|
|
222
|
-
curl http://localhost:9292/.well-known/openid-federation
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
**2. Test Client Entity Statement:**
|
|
226
|
-
```bash
|
|
227
|
-
curl http://localhost:9293/.well-known/openid-federation
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
**3. Test Login Flow:**
|
|
231
|
-
```bash
|
|
232
|
-
# Initiate login (will redirect to OP)
|
|
233
|
-
curl -L "http://localhost:9293/login?provider=https://op.example.com"
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
**4. Test Error Scenarios:**
|
|
237
|
-
```bash
|
|
238
|
-
# Invalid statement
|
|
239
|
-
curl "http://localhost:9292/.well-known/openid-federation?error_mode=invalid_statement"
|
|
240
|
-
|
|
241
|
-
# Wrong keys
|
|
242
|
-
curl "http://localhost:9292/.well-known/jwks.json?error_mode=wrong_keys"
|
|
243
|
-
|
|
244
|
-
# Expired statement
|
|
245
|
-
curl "http://localhost:9292/.well-known/openid-federation?error_mode=expired_statement"
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## Configuration
|
|
249
|
-
|
|
250
|
-
### OP Server Configuration
|
|
251
|
-
|
|
252
|
-
Create `examples/config/mock_op.yml`:
|
|
253
|
-
|
|
254
|
-
```yaml
|
|
255
|
-
entity_id: "https://op.example.com"
|
|
256
|
-
server_host: "localhost:9292"
|
|
257
|
-
signing_key: |
|
|
258
|
-
-----BEGIN RSA PRIVATE KEY-----
|
|
259
|
-
...
|
|
260
|
-
-----END RSA PRIVATE KEY-----
|
|
261
|
-
encryption_key: | # Optional, defaults to signing_key
|
|
262
|
-
-----BEGIN RSA PRIVATE KEY-----
|
|
263
|
-
...
|
|
264
|
-
-----END RSA PRIVATE KEY-----
|
|
265
|
-
trust_anchors:
|
|
266
|
-
- entity_id: "https://ta.example.com"
|
|
267
|
-
jwks:
|
|
268
|
-
keys:
|
|
269
|
-
- kty: "RSA"
|
|
270
|
-
kid: "ta-key-1"
|
|
271
|
-
use: "sig"
|
|
272
|
-
n: "..."
|
|
273
|
-
e: "AQAB"
|
|
274
|
-
authority_hints: # Optional, if OP is subordinate
|
|
275
|
-
- "https://ta.example.com"
|
|
276
|
-
op_metadata:
|
|
277
|
-
issuer: "https://op.example.com"
|
|
278
|
-
authorization_endpoint: "https://op.example.com/auth"
|
|
279
|
-
token_endpoint: "https://op.example.com/token"
|
|
280
|
-
request_object_encryption_alg_values_supported: ["RSA-OAEP"]
|
|
281
|
-
request_object_encryption_enc_values_supported: ["A128CBC-HS256"]
|
|
282
|
-
require_request_encryption: false # Set to true to require encryption
|
|
283
|
-
validate_request_objects: true # Set to false to skip validation
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### RP Server Configuration
|
|
287
|
-
|
|
288
|
-
Create `examples/config/mock_rp.yml`:
|
|
289
|
-
|
|
290
|
-
```yaml
|
|
291
|
-
entity_id: "https://rp.example.com"
|
|
292
|
-
server_host: "localhost:9293"
|
|
293
|
-
signing_key: |
|
|
294
|
-
-----BEGIN RSA PRIVATE KEY-----
|
|
295
|
-
...
|
|
296
|
-
-----END RSA PRIVATE KEY-----
|
|
297
|
-
encryption_key: | # Optional, for decrypting encrypted ID tokens
|
|
298
|
-
-----BEGIN RSA PRIVATE KEY-----
|
|
299
|
-
...
|
|
300
|
-
-----END RSA PRIVATE KEY-----
|
|
301
|
-
trust_anchors:
|
|
302
|
-
- entity_id: "https://ta.example.com"
|
|
303
|
-
jwks:
|
|
304
|
-
keys: [...]
|
|
305
|
-
authority_hints: # Optional, if RP is subordinate
|
|
306
|
-
- "https://ta.example.com"
|
|
307
|
-
redirect_uris:
|
|
308
|
-
- "https://rp.example.com/callback"
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
## Testing Scenarios
|
|
312
|
-
|
|
313
|
-
### Happy Path
|
|
314
|
-
|
|
315
|
-
1. Start both servers
|
|
316
|
-
2. Run integration tests: `ruby examples/integration_test_flow.rb`
|
|
317
|
-
3. All tests should pass
|
|
318
|
-
|
|
319
|
-
### Error Scenarios
|
|
320
|
-
|
|
321
|
-
1. Test invalid entity statement:
|
|
322
|
-
```bash
|
|
323
|
-
curl "http://localhost:9292/.well-known/openid-federation?error_mode=invalid_statement"
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
2. Test wrong keys:
|
|
327
|
-
```bash
|
|
328
|
-
curl "http://localhost:9292/.well-known/jwks.json?error_mode=wrong_keys"
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
3. Test expired statement:
|
|
332
|
-
```bash
|
|
333
|
-
curl "http://localhost:9292/.well-known/openid-federation?error_mode=expired_statement"
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
### Request Object Validation
|
|
337
|
-
|
|
338
|
-
1. Test with valid signed request object:
|
|
339
|
-
```bash
|
|
340
|
-
curl "http://localhost:9293/login?provider=https://op.example.com"
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
2. Test with invalid request object:
|
|
344
|
-
```bash
|
|
345
|
-
curl "http://localhost:9292/auth?error_mode=invalid_request&request=invalid.jwt"
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
### Trust Chain Resolution
|
|
349
|
-
|
|
350
|
-
1. Configure trust anchors in both servers
|
|
351
|
-
2. Ensure RP has authority_hints pointing to trust anchor
|
|
352
|
-
3. OP will resolve RP's trust chain during authorization
|
|
353
|
-
4. OP will apply metadata policies from trust chain
|
|
354
|
-
|
|
355
|
-
## Security Testing
|
|
356
|
-
|
|
357
|
-
The mock servers support security testing:
|
|
358
|
-
|
|
359
|
-
- **Algorithm Confusion**: Test rejection of non-RS256 algorithms
|
|
360
|
-
- **Key Confusion**: Test rejection of wrong keys
|
|
361
|
-
- **Signature Verification**: Test rejection of tampered signatures
|
|
362
|
-
- **Path Traversal**: Test rejection of malicious paths
|
|
363
|
-
- **Replay Attacks**: Test nonce validation
|
|
364
|
-
- **Request Object Validation**: Test signature and encryption validation
|
|
365
|
-
- **Trust Chain Validation**: Test authority hints and metadata policy enforcement
|
|
366
|
-
|
|
367
|
-
## Troubleshooting
|
|
368
|
-
|
|
369
|
-
### Server Won't Start
|
|
370
|
-
|
|
371
|
-
- Check if ports 9292 (OP) and 9293 (RP) are available
|
|
372
|
-
- Verify all dependencies are installed: `bundle install`
|
|
373
|
-
- Check configuration files exist and are valid YAML
|
|
374
|
-
|
|
375
|
-
### Entity Statements Not Validating
|
|
376
|
-
|
|
377
|
-
- Verify keys are correctly configured
|
|
378
|
-
- Check entity IDs match between servers
|
|
379
|
-
- Ensure trust anchors are configured if using trust chains
|
|
380
|
-
|
|
381
|
-
### Request Objects Rejected
|
|
382
|
-
|
|
383
|
-
- Verify RP's entity statement is accessible
|
|
384
|
-
- Check RP's JWKS contains the signing key
|
|
385
|
-
- Ensure request object is properly signed
|
|
386
|
-
- Verify encryption if required by OP
|
|
387
|
-
|
|
388
|
-
### Trust Chain Resolution Fails
|
|
389
|
-
|
|
390
|
-
- Verify trust anchors are configured
|
|
391
|
-
- Check authority_hints are correct
|
|
392
|
-
- Ensure all entity statements in chain are valid
|
|
393
|
-
- Verify subordinate statements are available
|
|
394
|
-
|
|
395
|
-
## Next Steps
|
|
396
|
-
|
|
397
|
-
1. **Add More Error Scenarios**: Extend error injection modes
|
|
398
|
-
2. **Performance Testing**: Add load testing scenarios
|
|
399
|
-
3. **Security Testing**: Add fuzzing and penetration tests
|
|
400
|
-
4. **Trust Mark Testing**: Add trust mark validation
|
|
401
|
-
5. Metadata Policy Testing: Add policy merging tests
|
|
402
|
-
|