class Virgil::Jwt::JwtHeaderContent

Represents header of [Jwt]

Constants

JWT_TYPE
VIRGIL_CONTENT_TYPE

Attributes

algorithm[R]

Signature algorithm @return [String]

content_type[R]

Access token content type. @return [String]

key_id[R]

Id of public key which is used for jwt signature verification. @return [String]

type[R]

Access token type. @return [String]

Public Class Methods

new(algorithm:, key_id:, type: JWT_TYPE, content_type: VIRGIL_CONTENT_TYPE) click to toggle source

Initializes a new instance of the class @param algorithm [String] signature algorithm @param type [String] access token type @param content_type [String] Access token content type @param key_id [String] API key id. Take it from {dashboard.virgilsecurity.com/api-keys}

# File lib/virgil/jwt/jwt_header_content.rb, line 63
def initialize(algorithm:, key_id:, type: JWT_TYPE, content_type: VIRGIL_CONTENT_TYPE)
  # todo validate
  @algorithm = algorithm
  @key_id = key_id
  @type = type
  @content_type = content_type
end
restore_from_json(str_json) click to toggle source

Restore header content from json @return [JwtHeaderContent]

# File lib/virgil/jwt/jwt_header_content.rb, line 85
def self.restore_from_json(str_json)
  model = JSON.parse(str_json)
  new(algorithm: model['alg'],
      key_id: model['kid'],
      type: model['typ'],
      content_type: model['cty'])
end

Public Instance Methods

to_json() click to toggle source

Json representation of header content @return [String]

# File lib/virgil/jwt/jwt_header_content.rb, line 73
def to_json
  model = {
    'alg': algorithm,
    'kid': key_id,
    'typ': type,
    'cty': content_type
  }
  model.to_json
end