Class: AtprotoAuth::DPoP::ProofGenerator
- Inherits:
-
Object
- Object
- AtprotoAuth::DPoP::ProofGenerator
- Defined in:
- lib/atproto_auth/dpop/proof_generator.rb
Overview
Creates and manages DPoP proof JWTs according to RFC 9449. DPoP proofs are used to prove possession of a key when making HTTP requests. Each proof is a JWT that includes details about the request and is signed by the DPoP key.
Defined Under Namespace
Classes: ProofError
Instance Attribute Summary collapse
-
#key_manager ⇒ KeyManager
readonly
The key manager used for signing proofs.
Instance Method Summary collapse
-
#generate(http_method:, http_uri:, nonce: nil, access_token: nil, ath: nil) ⇒ String
Generates a new DPoP proof JWT for an HTTP request.
-
#initialize(key_manager) ⇒ ProofGenerator
constructor
Creates a new ProofGenerator instance.
Constructor Details
#initialize(key_manager) ⇒ ProofGenerator
Creates a new ProofGenerator instance
22 23 24 25 26 27 |
# File 'lib/atproto_auth/dpop/proof_generator.rb', line 22 def initialize(key_manager) raise ProofError, "key_manager is required" unless key_manager raise ProofError, "invalid key_manager type" unless key_manager.is_a?(KeyManager) @key_manager = key_manager end |
Instance Attribute Details
#key_manager ⇒ KeyManager (readonly)
Returns The key manager used for signing proofs.
17 18 19 |
# File 'lib/atproto_auth/dpop/proof_generator.rb', line 17 def key_manager @key_manager end |
Instance Method Details
#generate(http_method:, http_uri:, nonce: nil, access_token: nil, ath: nil) ⇒ String
Generates a new DPoP proof JWT for an HTTP request
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/atproto_auth/dpop/proof_generator.rb', line 37 def generate(http_method:, http_uri:, nonce: nil, access_token: nil, ath: nil) validate_inputs!(http_method, http_uri) ath = !access_token.nil? if ath.nil? header = build_header payload = build_payload( http_method: http_method, http_uri: http_uri, nonce: nonce, access_token: access_token, include_ath: ath ) key_manager.sign_segments(header, payload) rescue StandardError => e raise ProofError, "Failed to generate proof: #{e.}" end |