Module: JWT::Claims

Defined in:
lib/jwt/claims.rb,
lib/jwt/claims/issuer.rb,
lib/jwt/claims/jwt_id.rb,
lib/jwt/claims/numeric.rb,
lib/jwt/claims/subject.rb,
lib/jwt/claims/audience.rb,
lib/jwt/claims/required.rb,
lib/jwt/claims/verifier.rb,
lib/jwt/claims/issued_at.rb,
lib/jwt/claims/expiration.rb,
lib/jwt/claims/not_before.rb,
lib/jwt/claims/decode_verifier.rb,
lib/jwt/claims/verification_methods.rb

Overview

JWT Claim verifications datatracker.ietf.org/doc/html/rfc7519#section-4

Verification is supported for the following claims: exp nbf iss iat jti aud sub required numeric

Defined Under Namespace

Modules: DecodeVerifier, VerificationMethods, Verifier Classes: Audience, Error, Expiration, IssuedAt, Issuer, JwtId, NotBefore, Numeric, Required, Subject, VerificationContext

Class Method Summary collapse

Class Method Details

.payload_errors(payload, *options) ⇒ Array<JWT::Claims::Error>

Returns the errors in the claims of the JWT token.

Parameters:

  • options (Array)

    the options for verifying the claims.

Returns:



69
70
71
# File 'lib/jwt/claims.rb', line 69

def payload_errors(payload, *options)
  Verifier.errors(VerificationContext.new(payload: payload), *options)
end

.valid_payload?(payload, *options) ⇒ Boolean

Checks if the claims in the JWT payload are valid.

Parameters:

  • payload (Hash)

    the JWT payload.

  • options (Array)

    the options for verifying the claims.

Returns:

  • (Boolean)

    true if the claims are valid, false otherwise



61
62
63
# File 'lib/jwt/claims.rb', line 61

def valid_payload?(payload, *options)
  payload_errors(payload, *options).empty?
end

.verify!(payload, options) ⇒ Object

Deprecated.

Use verify_payload! instead. Will be removed in the next major version of ruby-jwt.



37
38
39
40
# File 'lib/jwt/claims.rb', line 37

def verify!(payload, options)
  Deprecations.warning('The ::JWT::Claims.verify! method is deprecated will be removed in the next major version of ruby-jwt')
  DecodeVerifier.verify!(payload, options)
end

.verify_payload!(payload, *options) ⇒ void

This method returns an undefined value.

Checks if the claims in the JWT payload are valid.

Examples:


::JWT::Claims.verify_payload!({"exp" => Time.now.to_i + 10}, :exp)
::JWT::Claims.verify_payload!({"exp" => Time.now.to_i - 10}, exp: { leeway: 11})

Parameters:

  • payload (Hash)

    the JWT payload.

  • options (Array)

    the options for verifying the claims.

Raises:



52
53
54
# File 'lib/jwt/claims.rb', line 52

def verify_payload!(payload, *options)
  Verifier.verify!(VerificationContext.new(payload: payload), *options)
end