module JWT
Should be up to date with the latest spec: tools.ietf.org/html/rfc7519
Should be up to date with the latest spec: tools.ietf.org/html/rfc7519
Public Class Methods
Source
# File lib/jwt/version.rb, line 11 def self.gem_version Gem::Version.new(VERSION::STRING) end
Returns the gem version of the JWT
library.
@return [Gem::Version] the gem version.
Source
# File lib/jwt/version.rb, line 29 def self.openssl_3? return false if OpenSSL::OPENSSL_VERSION.include?('LibreSSL') true if 3 * 0x10000000 <= OpenSSL::OPENSSL_VERSION_NUMBER end
Checks if the OpenSSL version is 3 or greater.
@return [Boolean] true if OpenSSL version is 3 or greater, false otherwise. @api private
Source
# File lib/jwt/version.rb, line 55 def self.openssl_3_hmac_empty_key_regression? openssl_3? && openssl_version <= ::Gem::Version.new('3.0.0') end
Checks if there is an OpenSSL 3 HMAC empty key regression.
@return [Boolean] true if there is an OpenSSL 3 HMAC empty key regression, false otherwise. @api private
Source
# File lib/jwt/version.rb, line 63 def self.openssl_version @openssl_version ||= ::Gem::Version.new(OpenSSL::VERSION) end
Returns the OpenSSL version.
@return [Gem::Version] the OpenSSL version. @api private
Source
# File lib/jwt/version.rb, line 39 def self.rbnacl? defined?(::RbNaCl) end
Checks if the RbNaCl library is defined.
@return [Boolean] true if RbNaCl is defined, false otherwise. @api private
Source
# File lib/jwt/version.rb, line 47 def self.rbnacl_6_or_greater? rbnacl? && ::Gem::Version.new(::RbNaCl::VERSION) >= ::Gem::Version.new('6.0.0') end
Checks if the RbNaCl library version is 6.0.0 or greater.
@return [Boolean] true if RbNaCl version is 6.0.0 or greater, false otherwise. @api private
Public Instance Methods
Source
# File lib/jwt.rb, line 49 def decode(jwt, key = nil, verify = true, options = {}, &keyfinder) # rubocop:disable Style/OptionalBooleanParameter Deprecations.context do Decode.new(jwt, key, verify, configuration.decode.to_h.merge(options), &keyfinder).decode_segments end end
Decodes a JWT
to extract the payload and header
@param jwt [String] the JWT
to decode. @param key [String] the key used to verify the JWT
. @param verify [Boolean] whether to verify the JWT
signature. @param options [Hash] additional options for decoding. @return [Array<Hash>] the decoded payload and headers.
Source
# File lib/jwt.rb, line 35 def encode(payload, key, algorithm = 'HS256', header_fields = {}) Encode.new(payload: payload, key: key, algorithm: algorithm, headers: header_fields).segments end
Encodes a payload into a JWT
.
@param payload [Hash] the payload to encode. @param key [String] the key used to sign the JWT
. @param algorithm [String] the algorithm used to sign the JWT
. @param header_fields [Hash] additional headers to include in the JWT
. @return [String] the encoded JWT
.