Class: Rack::Auth::Signature
- Inherits:
-
Object
- Object
- Rack::Auth::Signature
- Includes:
- Helpers
- Defined in:
- lib/rack/auth/signature.rb,
lib/rack/auth/signature/helpers.rb
Overview
Rack middleware for HTTP Message Signature verification (RFC 9421).
This middleware verifies that incoming requests have valid HTTP signatures. Requests without valid signatures are rejected with a 401 Unauthorized response.
Configuration file format (YAML):
signatures:
reject_older_than: 900 # Reject signatures older than 15 minutes
created_required: true # Require 'created' parameter
keyid_required: false # Require 'keyid' parameter
covered_components: # Required components in signature
- "@method"
- "@request-target"
- "date"
keys:
my-key-id:
alg: ed25519
material: | # Inline PEM
-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----
other-key:
alg: rsa-pss-sha512
path: keys/public.pem # Or path to key file
Defined Under Namespace
Modules: Helpers
Instance Method Summary collapse
-
#call(env) ⇒ Array
Processes an incoming request.
-
#initialize(app, options = {}) { ... } ⇒ Signature
constructor
Creates a new signature verification middleware.
Methods included from Helpers::Configuration
Constructor Details
#initialize(app, options = {}) { ... } ⇒ Signature
Creates a new signature verification middleware.
81 82 83 84 85 |
# File 'lib/rack/auth/signature.rb', line 81 def initialize(app, = {}, &block) @app = app = (Hash()) instance_eval(&block) if block end |
Instance Method Details
#call(env) ⇒ Array
Processes an incoming request.
If the request path is excluded or the signature is valid, the request is passed to the wrapped application. Otherwise, returns a 401 response.
On successful verification, the signature is stored in ‘env` for use by the application.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rack/auth/signature.rb', line 97 def call(env) @request = Rack::Request.new(env) if excluded? || allowed? @app.call(env) else response = [:signatures][:error_response].values Rack::Response.new(*response).finish end end |