Module: StandardId::Oauth::ConsentPayload

Defined in:
lib/standard_id/oauth/consent_payload.rb

Overview

Tamper-proof carrier for the original /authorize parameters across the consent hand-off (API authorize -> WebEngine consent screen -> resume).

Mirrors the OTP flow’s use of Rails.application.message_verifier: the params are signed (not encrypted — they are not secret, but must not be mutable by the user) and expire so a stale consent link can’t be replayed indefinitely. redirect_uri and PKCE are revalidated when the resumed /authorize re-runs, so signing here defends the integrity of the carried values, not the eventual code issuance.

Constant Summary collapse

VERIFIER_PURPOSE =
:standard_id_oauth_consent
DEFAULT_EXPIRY =

Generous TTL: the user may take a while to read the consent screen.

600

Class Method Summary collapse

Class Method Details

.decode(token) ⇒ Object

Returns the params Hash (symbolized keys) or nil if the payload is missing, tampered, or expired.



25
26
27
28
29
# File 'lib/standard_id/oauth/consent_payload.rb', line 25

def decode(token)
  return nil if token.blank?

  verifier.verified(token)&.symbolize_keys
end

.encode(params, expires_in: DEFAULT_EXPIRY) ⇒ Object



19
20
21
# File 'lib/standard_id/oauth/consent_payload.rb', line 19

def encode(params, expires_in: DEFAULT_EXPIRY)
  verifier.generate(params.to_h.symbolize_keys, expires_in: expires_in.seconds)
end

.verifierObject



31
32
33
# File 'lib/standard_id/oauth/consent_payload.rb', line 31

def verifier
  Rails.application.message_verifier(VERIFIER_PURPOSE)
end