omniauth_openid_federation 2.2.0 → 2.2.1

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: 06eb00cceeca266e7eb952398a2b89ce9fb6c01e537e4f3bcf39d0c3b4e2d633
4
- data.tar.gz: 378844a5fb14eae224fad9a7d1fc2d6fc5a9689d6635645d625d83c3f35dc30f
3
+ metadata.gz: fc8b81ae98a1cd6d1c6c5477fb7ce07c0740e2db5d88359d3ec4e8178b3629ee
4
+ data.tar.gz: d5efb3c2d67c34168d98ba9fd32d43370a026928266d6e705fe7e5e9afcb0727
5
5
  SHA512:
6
- metadata.gz: 5c069f152a683f084e002aac4ba0c15f61875a7fb1a3586a2d93747275fbcefef2a67a370f9562afff46e4f9b94f6de0ac419381b7d4b994b046525962165bc6
7
- data.tar.gz: d533de4e933a346235f4c948e62bf66e8b05c4218528e5956974407ca5485ac0f5e332f47681f3e85942fe0df244f94053f81bb5bfaa3bc324063769bbdfc857
6
+ metadata.gz: 15c5866a887010902bf60107b4e3f8395e58f21f97822e1dad0b0111dc1edb28978c99d22104b43a6c3bc0a1ca7a746347d6c154b269227d46daebeb9b85219e
7
+ data.tar.gz: c341bd06f43bc8f4e9433d8add62d5cd477b15c713992ce62eaf2d7c3bade6d3140735e5badd9c610ccb491bc1adf70995ceac3765760e4ee5bf0044b612ab43
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.2.1 (2026-11-11)
6
+
7
+ - 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)
8
+ - Add `OmniauthOpenidFederation.draw_well_known_routes` for host-drawn well-known paths; share route definitions with the Engine
9
+ - Add optional `encrypt` / `decrypt` callables on `RelyingPartyKeyStore::CacheStore` (default remains plaintext PEM through the cache adapter)
10
+
5
11
  ## 2.2.0 (2026-11-11)
6
12
 
7
13
  - Fix Rack well-known entity configuration responses to use `application/entity-statement+jwt`
data/README.md CHANGED
@@ -209,19 +209,27 @@ end
209
209
 
210
210
  ### Step 6: Add Routes
211
211
 
212
+ Well-known paths must sit at site root (`/.well-known/...`). Put one of these inside a single `Rails.application.routes.draw` block. A nested second `routes.draw` clears earlier routes in that file, including an Engine mount.
213
+
212
214
  ```ruby
213
215
  # config/routes.rb
214
- if ENV["OPENID_ENABLED"] == "true"
215
- mount OmniauthOpenidFederation::Engine => "/"
216
- end
217
-
218
216
  Rails.application.routes.draw do
217
+ if ENV["OPENID_ENABLED"] == "true"
218
+ # Option A: mount Engine at site root
219
+ mount OmniauthOpenidFederation::Engine => "/"
220
+
221
+ # Option B (API / feature-flag hosts): draw the same controller actions on the host
222
+ # OmniauthOpenidFederation.draw_well_known_routes(self)
223
+ end
224
+
219
225
  devise_for :users, controllers: {
220
226
  omniauth_callbacks: "users/omniauth_callbacks"
221
227
  }
222
228
  end
223
229
  ```
224
230
 
231
+ For hosts that must stay outside Action Controller filters, use Rack instead of the Engine (see Installation).
232
+
225
233
  ### Step 7: Create Callback Controller
226
234
 
227
235
  ```ruby
@@ -297,7 +305,7 @@ Use `prepare_request_object_params` proc to modify parameters before they're add
297
305
 
298
306
  ```ruby
299
307
  config.omniauth :openid_federation,
300
- request_object_params: [:ftn_spname], # Allow-list for provider-specific params (example: Finnish FTN)
308
+ request_object_params: [:ftn_spname], # Allow-list for provider-specific params (example claim name)
301
309
  default_request_object_claims: {
302
310
  ui_locales: "fi",
303
311
  acr_values: ENV["OPENID_ACR_VALUES"]
data/config/routes.rb CHANGED
@@ -1,30 +1,15 @@
1
- # Routes for OpenID Federation well-known endpoints
2
- # These routes are mounted at the root level (not namespaced) because
3
- # OpenID Federation spec requires specific well-known paths
4
- # Guard to prevent double-loading routes (important for test isolation)
5
- # Use a file-level instance variable that doesn't trigger class loading
1
+ # Routes for OpenID Federation well-known endpoints.
2
+ # Spec requires site-root paths; mount the Engine at "/" or draw these on the host.
3
+ # Guard to prevent double-loading routes (important for test isolation).
6
4
  @_omniauth_openid_federation_routes_loaded ||= false
7
5
  unless @_omniauth_openid_federation_routes_loaded
8
6
  @_omniauth_openid_federation_routes_loaded = true
9
7
  begin
8
+ require_relative "../lib/omniauth_openid_federation/well_known_routes"
10
9
  OmniauthOpenidFederation::Engine.routes.draw do
11
- # OpenID Federation 1.0 Section 9: Entity Configuration endpoint
12
- # MUST be at /.well-known/openid-federation
13
- get "/.well-known/openid-federation", to: "omniauth_openid_federation/federation#show", as: :openid_federation
14
-
15
- # Fetch endpoint for Subordinate Statements (Section 6.1)
16
- get "/.well-known/openid-federation/fetch", to: "omniauth_openid_federation/federation#fetch", as: :openid_federation_fetch
17
-
18
- # Standard JWKS endpoint
19
- get "/.well-known/jwks.json", to: "omniauth_openid_federation/federation#jwks", as: :openid_federation_jwks
20
-
21
- # Signed JWKS endpoint (OpenID Federation requirement)
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
10
+ OmniauthOpenidFederation::WellKnownRoutes.draw(self)
26
11
  end
27
12
  rescue NameError, LoadError
28
- # Rails not available or not fully initialized - routes will be loaded when Engine initializes
13
+ # Rails not available or not fully initialized - routes load when Engine initializes
29
14
  end
30
15
  end
@@ -1,7 +1,12 @@
1
1
  # Example: rotate RP signing/encryption keys and refresh served JWKS without restart.
2
2
  #
3
+ # CacheStore writes PEM through CacheAdapter. Default is plaintext. For shared or
4
+ # durable caches, pass encrypt/decrypt callables (cipher and KMS stay host-owned):
5
+ #
3
6
  # store = OmniauthOpenidFederation::RelyingPartyKeyStore::CacheStore.new(
4
- # cache_key_prefix: "openid_federation/rp_keys"
7
+ # cache_key_prefix: "openid_federation/rp_keys",
8
+ # encrypt: ->(pem) { HostKeySeal.seal(pem) },
9
+ # decrypt: ->(blob) { HostKeySeal.open(blob) }
5
10
  # )
6
11
  # record = store.rotate
7
12
  #
@@ -15,7 +15,7 @@ module OmniauthOpenidFederation
15
15
  # Use Configuration.config.max_string_length for runtime configuration instead of patching this constant
16
16
  MAX_STRING_LENGTH = 8192
17
17
 
18
- # Minimum RSA modulus size for OIDC signing and encryption keys (FTN and common federation profiles)
18
+ # Minimum RSA modulus size for OIDC signing and encryption keys (common federation profiles)
19
19
  MIN_RSA_KEY_BITS = 2048
20
20
 
21
21
  # Maximum HTTP response body size for federation/JWKS fetches (1 MiB)
@@ -1,11 +1,18 @@
1
1
  # Rails Engine for OpenID Federation endpoints
2
2
  # Provides controllers and routes for well-known OpenID Federation endpoints
3
3
  #
4
+ # Mount at site root inside a single host `routes.draw` block:
5
+ # mount OmniauthOpenidFederation::Engine => "/"
6
+ # Or draw the same paths on the host:
7
+ # OmniauthOpenidFederation.draw_well_known_routes(self)
8
+ #
9
+ # @see OmniauthOpenidFederation::WellKnownRoutes
4
10
  # @see https://guides.rubyonrails.org/engines.html Rails Engines Guide
11
+ require_relative "well_known_routes"
12
+
5
13
  module OmniauthOpenidFederation
6
14
  class Engine < ::Rails::Engine
7
- # Don't isolate namespace because we need routes at specific well-known paths
8
- # (/.well-known/openid-federation) rather than under a mount point
15
+ # Not isolated: well-known paths must stay at site root under mount "/".
9
16
 
10
17
  initializer "omniauth_openid_federation.append_controller_paths", before: :set_load_path do |app|
11
18
  controllers = root.join("app", "controllers")
@@ -466,18 +466,15 @@ module OmniauthOpenidFederation
466
466
  RackEndpoint.new
467
467
  end
468
468
 
469
- # Mount the federation endpoint routes in Rails routes
469
+ # Mount or draw well-known routes inside one host routes.draw block:
470
+ # mount OmniauthOpenidFederation::Engine => "/"
471
+ # # or OmniauthOpenidFederation.draw_well_known_routes(self)
470
472
  #
471
- # RECOMMENDED: Use the Engine (Rails-idiomatic way):
472
- # Rails.application.routes.draw do
473
- # mount OmniauthOpenidFederation::Engine => "/"
474
- # end
475
- #
476
- # This mounts all four endpoints at the root level:
477
- # - GET /.well-known/openid-federation (entity statement)
478
- # - GET /.well-known/openid-federation/fetch (fetch endpoint for Subordinate Statements)
479
- # - GET /.well-known/jwks.json (standard JWKS)
480
- # - GET /.well-known/signed-jwks.json (signed JWKS)
473
+ # Paths:
474
+ # - GET /.well-known/openid-federation
475
+ # - GET /.well-known/openid-federation/fetch
476
+ # - GET /.well-known/jwks.json
477
+ # - GET /.well-known/signed-jwks.json|.jwt|.jose
481
478
  #
482
479
 
483
480
  # Generate fresh signing and encryption keys and write entity statement to file
@@ -9,8 +9,10 @@
9
9
  # require "omniauth_openid_federation/rails"
10
10
  # OmniauthOpenidFederation.base_controller = "ActionController::API" # optional
11
11
  #
12
- # Prefer mounting OmniauthOpenidFederation::Engine, or use RackEndpoint alone for
13
- # hosts that must stay outside Action Controller filters.
12
+ # Prefer one of:
13
+ # mount OmniauthOpenidFederation::Engine => "/" # inside a single routes.draw
14
+ # OmniauthOpenidFederation.draw_well_known_routes(self)
15
+ # RackEndpoint under map "/.well-known" for hosts outside Action Controller
14
16
  require "omniauth_openid_federation"
15
17
 
16
18
  unless defined?(Rails)
@@ -74,29 +74,41 @@ module OmniauthOpenidFederation
74
74
  end
75
75
  end
76
76
 
77
+ # Cache-backed RP private keys.
78
+ #
79
+ # Default writes PEM strings through CacheAdapter with no confidentiality layer.
80
+ # Shared or durable cache backends need host-provided `encrypt` / `decrypt`
81
+ # callables, or a backend that already encrypts values at rest. Cipher choice
82
+ # and key custody stay a host concern.
77
83
  class CacheStore < RelyingPartyKeyStore
78
84
  SIGNING_SUFFIX = "signing_pem"
79
85
  ENCRYPTION_SUFFIX = "encryption_pem"
80
86
 
81
- def initialize(cache_key_prefix:, expires_in: nil)
87
+ # @param cache_key_prefix [String] shared prefix for signing and encryption entries
88
+ # @param expires_in [Integer, nil] optional CacheAdapter TTL
89
+ # @param encrypt [Proc, nil] transform PEM string before write (default: identity)
90
+ # @param decrypt [Proc, nil] transform stored blob after read (default: identity)
91
+ def initialize(cache_key_prefix:, expires_in: nil, encrypt: nil, decrypt: nil)
82
92
  @prefix = cache_key_prefix
83
93
  @expires_in = expires_in
94
+ @encrypt = encrypt || ->(pem) { pem }
95
+ @decrypt = decrypt || ->(blob) { blob }
84
96
  end
85
97
 
86
98
  def load
87
- signing_pem = CacheAdapter.read(key(SIGNING_SUFFIX))
88
- encryption_pem = CacheAdapter.read(key(ENCRYPTION_SUFFIX))
89
- raise ConfigurationError, "RP keys missing from cache (#{@prefix})" if signing_pem.nil? || encryption_pem.nil?
99
+ signing_blob = CacheAdapter.read(key(SIGNING_SUFFIX))
100
+ encryption_blob = CacheAdapter.read(key(ENCRYPTION_SUFFIX))
101
+ raise ConfigurationError, "RP keys missing from cache (#{@prefix})" if signing_blob.nil? || encryption_blob.nil?
90
102
 
91
103
  Record.new(
92
- signing_key: OpenSSL::PKey::RSA.new(signing_pem),
93
- encryption_key: OpenSSL::PKey::RSA.new(encryption_pem)
104
+ signing_key: OpenSSL::PKey::RSA.new(@decrypt.call(signing_blob)),
105
+ encryption_key: OpenSSL::PKey::RSA.new(@decrypt.call(encryption_blob))
94
106
  )
95
107
  end
96
108
 
97
109
  def store(signing_key:, encryption_key:)
98
- CacheAdapter.write(key(SIGNING_SUFFIX), signing_key.to_pem, expires_in: @expires_in)
99
- CacheAdapter.write(key(ENCRYPTION_SUFFIX), encryption_key.to_pem, expires_in: @expires_in)
110
+ CacheAdapter.write(key(SIGNING_SUFFIX), @encrypt.call(signing_key.to_pem), expires_in: @expires_in)
111
+ CacheAdapter.write(key(ENCRYPTION_SUFFIX), @encrypt.call(encryption_key.to_pem), expires_in: @expires_in)
100
112
  Record.new(signing_key: signing_key, encryption_key: encryption_key)
101
113
  end
102
114
 
@@ -1,3 +1,3 @@
1
1
  module OmniauthOpenidFederation
2
- VERSION = "2.2.0".freeze
2
+ VERSION = "2.2.1".freeze
3
3
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniauthOpenidFederation
4
+ # Shared well-known route definitions for Engine mount and host draw.
5
+ #
6
+ # Supported host patterns (pick one):
7
+ # 1. `mount OmniauthOpenidFederation::Engine => "/"` inside a single `routes.draw` block
8
+ # 2. `OmniauthOpenidFederation.draw_well_known_routes(self)` inside the host `routes.draw`
9
+ # 3. Rack: `map "/.well-known" { run RackEndpoint.new }`
10
+ #
11
+ # Do not call `Rails.application.routes.draw` again inside `config/routes.rb`; a second
12
+ # draw clears routes already registered in that file, including an Engine mount.
13
+ module WellKnownRoutes
14
+ module_function
15
+
16
+ # @param mapper [ActionDispatch::Routing::Mapper]
17
+ def draw(mapper)
18
+ mapper.instance_eval do
19
+ get "/.well-known/openid-federation",
20
+ to: "omniauth_openid_federation/federation#show",
21
+ as: :openid_federation
22
+
23
+ get "/.well-known/openid-federation/fetch",
24
+ to: "omniauth_openid_federation/federation#fetch",
25
+ as: :openid_federation_fetch
26
+
27
+ get "/.well-known/jwks.json",
28
+ to: "omniauth_openid_federation/federation#jwks",
29
+ as: :openid_federation_jwks
30
+
31
+ get "/.well-known/signed-jwks.json",
32
+ to: "omniauth_openid_federation/federation#signed_jwks",
33
+ as: :openid_federation_signed_jwks
34
+
35
+ get "/.well-known/signed-jwks.jwt",
36
+ to: "omniauth_openid_federation/federation#signed_jwks",
37
+ as: :openid_federation_signed_jwks_jwt
38
+
39
+ get "/.well-known/signed-jwks.jose",
40
+ to: "omniauth_openid_federation/federation#signed_jwks",
41
+ as: :openid_federation_signed_jwks_jose
42
+ end
43
+ end
44
+ end
45
+
46
+ # Draw absolute well-known routes on the host application mapper.
47
+ #
48
+ # @param mapper [ActionDispatch::Routing::Mapper]
49
+ # @example
50
+ # Rails.application.routes.draw do
51
+ # OmniauthOpenidFederation.draw_well_known_routes(self) if ENV["OPENID_ENABLED"] == "true"
52
+ # end
53
+ def self.draw_well_known_routes(mapper)
54
+ WellKnownRoutes.draw(mapper)
55
+ end
56
+ end
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.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
@@ -556,6 +556,7 @@ files:
556
556
  - lib/omniauth_openid_federation/utils.rb
557
557
  - lib/omniauth_openid_federation/validators.rb
558
558
  - lib/omniauth_openid_federation/version.rb
559
+ - lib/omniauth_openid_federation/well_known_routes.rb
559
560
  - lib/tasks/omniauth_openid_federation.rake
560
561
  - sig/federation.rbs
561
562
  - sig/jwks.rbs