Class: Virgil::Jwt::JwtHeaderContent
- Inherits:
-
Object
- Object
- Virgil::Jwt::JwtHeaderContent
- Defined in:
- lib/virgil/jwt/jwt_header_content.rb
Overview
Represents header of [Jwt]
Constant Summary collapse
- VIRGIL_CONTENT_TYPE =
'virgil-jwt;v=1'.freeze
- JWT_TYPE =
'JWT'.freeze
Instance Attribute Summary collapse
-
#algorithm ⇒ String
readonly
Signature algorithm.
-
#content_type ⇒ String
readonly
Access token content type.
-
#key_id ⇒ String
readonly
Id of public key which is used for jwt signature verification.
-
#type ⇒ String
readonly
Access token type.
Class Method Summary collapse
-
.restore_from_json(str_json) ⇒ JwtHeaderContent
Restore header content from json.
Instance Method Summary collapse
-
#initialize(algorithm:, key_id:, type: JWT_TYPE, content_type: VIRGIL_CONTENT_TYPE) ⇒ JwtHeaderContent
constructor
Initializes a new instance of the class.
-
#to_json ⇒ String
Json representation of header content.
Constructor Details
#initialize(algorithm:, key_id:, type: JWT_TYPE, content_type: VIRGIL_CONTENT_TYPE) ⇒ JwtHeaderContent
Initializes a new instance of the class
63 64 65 66 67 68 69 |
# 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 |
Instance Attribute Details
#algorithm ⇒ String (readonly)
Signature algorithm
44 45 46 |
# File 'lib/virgil/jwt/jwt_header_content.rb', line 44 def algorithm @algorithm end |
#content_type ⇒ String (readonly)
Access token content type.
52 53 54 |
# File 'lib/virgil/jwt/jwt_header_content.rb', line 52 def content_type @content_type end |
#key_id ⇒ String (readonly)
Id of public key which is used for jwt signature verification.
56 57 58 |
# File 'lib/virgil/jwt/jwt_header_content.rb', line 56 def key_id @key_id end |
#type ⇒ String (readonly)
Access token type.
48 49 50 |
# File 'lib/virgil/jwt/jwt_header_content.rb', line 48 def type @type end |
Class Method Details
.restore_from_json(str_json) ⇒ JwtHeaderContent
Restore header content from json
85 86 87 88 89 90 91 |
# 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 |
Instance Method Details
#to_json ⇒ String
Json representation of header content
73 74 75 76 77 78 79 80 81 |
# 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 |