Class: JWT::Claims::Issuer

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt/claims/issuer.rb

Overview

The Issuer class is responsible for validating the issuer claim (‘iss’) in a JWT token.

Instance Method Summary collapse

Constructor Details

#initialize(issuers:) ⇒ Issuer

Initializes a new Issuer instance.

Parameters:

  • issuers (String, Symbol, Array<String, Symbol>)

    the expected issuer(s) for the JWT token.



10
11
12
# File 'lib/jwt/claims/issuer.rb', line 10

def initialize(issuers:)
  @issuers = Array(issuers).map { |item| item.is_a?(Symbol) ? item.to_s : item }
end

Instance Method Details

#verify!(context:, **_args) ⇒ nil

Verifies the issuer claim (‘iss’) in the JWT token.

Parameters:

  • context (Object)

    the context containing the JWT payload.

  • _args (Hash)

    additional arguments (not used).

Returns:

  • (nil)

Raises:



20
21
22
23
24
25
26
27
# File 'lib/jwt/claims/issuer.rb', line 20

def verify!(context:, **_args)
  case (iss = context.payload['iss'])
  when *issuers
    nil
  else
    raise JWT::InvalidIssuerError, "Invalid issuer. Expected #{issuers}, received #{iss || '<none>'}"
  end
end