Class: JWT::Claims::Subject
- Inherits:
-
Object
- Object
- JWT::Claims::Subject
- Defined in:
- lib/jwt/claims/subject.rb
Overview
The Subject class is responsible for validating the subject claim (‘sub’) in a JWT token.
Instance Method Summary collapse
-
#initialize(expected_subject:) ⇒ Subject
constructor
Initializes a new Subject instance.
-
#verify!(context:, **_args) ⇒ nil
Verifies the subject claim (‘sub’) in the JWT token.
Constructor Details
#initialize(expected_subject:) ⇒ Subject
Initializes a new Subject instance.
10 11 12 |
# File 'lib/jwt/claims/subject.rb', line 10 def initialize(expected_subject:) @expected_subject = expected_subject.to_s end |
Instance Method Details
#verify!(context:, **_args) ⇒ nil
Verifies the subject claim (‘sub’) in the JWT token.
20 21 22 23 |
# File 'lib/jwt/claims/subject.rb', line 20 def verify!(context:, **_args) sub = context.payload['sub'] raise(JWT::InvalidSubError, "Invalid subject. Expected #{expected_subject}, received #{sub || '<none>'}") unless sub.to_s == expected_subject end |