Sha256: e8bd97644e37e1fae2fba613b7f5e9aa4b4c662bde5f8329b6da0735d34477e2

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module JWT
  module Claims
    # The Audience class is responsible for validating the audience claim ('aud') in a JWT token.
    class Audience
      # Initializes a new Audience instance.
      #
      # @param expected_audience [String, Array<String>] the expected audience(s) for the JWT token.
      def initialize(expected_audience:)
        @expected_audience = expected_audience
      end

      # Verifies the audience claim ('aud') in the JWT token.
      #
      # @param context [Object] the context containing the JWT payload.
      # @param _args [Hash] additional arguments (not used).
      # @raise [JWT::InvalidAudError] if the audience claim is invalid.
      # @return [nil]
      def verify!(context:, **_args)
        aud = context.payload['aud']
        raise JWT::InvalidAudError, "Invalid audience. Expected #{expected_audience}, received #{aud || '<none>'}" if ([*aud] & [*expected_audience]).empty?
      end

      private

      attr_reader :expected_audience
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/jwt-2.10.1/lib/jwt/claims/audience.rb
jwt-2.10.1 lib/jwt/claims/audience.rb
jwt-2.10.0 lib/jwt/claims/audience.rb