Class: OmniauthOpenidFederation::JwtResponseDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth_openid_federation/jwt_response_decoder.rb

Overview

Decrypts and verifies compact JWE/JWS response bodies (nested JWTs).

Constant Summary collapse

COMPACT_TOKEN_PATTERN =
/\A[\w\-.]+\z/

Instance Method Summary collapse

Constructor Details

#initialize(strategy_options:, client: nil) ⇒ JwtResponseDecoder

Returns a new instance of JwtResponseDecoder.



22
23
24
25
# File 'lib/omniauth_openid_federation/jwt_response_decoder.rb', line 22

def initialize(strategy_options:, client: nil)
  @strategy_options = strategy_options
  @client = client
end

Instance Method Details

#decode(body) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/omniauth_openid_federation/jwt_response_decoder.rb', line 27

def decode(body)
  body_text = body.to_s.strip
  return {} if OmniauthOpenidFederation::StringHelpers.blank?(body_text)

  unless compact_token?(body_text)
    return OmniauthOpenidFederation::Utils.to_indifferent_hash(JSON.parse(body_text))
  end

  signed_jwt = resolve_signed_jwt(body_text)
  return OmniauthOpenidFederation::Utils.to_indifferent_hash(signed_jwt) if signed_jwt.is_a?(Hash)

  payload = verify_signed_jwt(signed_jwt)
  OmniauthOpenidFederation::Utils.to_indifferent_hash(payload)
end