Class: JWT::Claims::Audience
- Inherits:
-
Object
- Object
- JWT::Claims::Audience
- Defined in:
- lib/jwt/claims/audience.rb
Overview
The Audience class is responsible for validating the audience claim (‘aud’) in a JWT token.
Instance Method Summary collapse
-
#initialize(expected_audience:) ⇒ Audience
constructor
Initializes a new Audience instance.
-
#verify!(context:, **_args) ⇒ nil
Verifies the audience claim (‘aud’) in the JWT token.
Constructor Details
#initialize(expected_audience:) ⇒ Audience
Initializes a new Audience instance.
10 11 12 |
# File 'lib/jwt/claims/audience.rb', line 10 def initialize(expected_audience:) @expected_audience = expected_audience end |
Instance Method Details
#verify!(context:, **_args) ⇒ nil
Verifies the audience claim (‘aud’) in the JWT token.
20 21 22 23 |
# File 'lib/jwt/claims/audience.rb', line 20 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 |