Class: Virgil::Jwt::JwtBodyContent
- Inherits:
-
Object
- Object
- Virgil::Jwt::JwtBodyContent
- Defined in:
- lib/virgil/jwt/jwt_body_content.rb
Overview
Represents content of [Jwt]
Constant Summary collapse
- IDENTITY_PREFIX =
'identity-'.freeze
- SUBJECT_PREFIX =
'virgil-'.freeze
Instance Attribute Summary collapse
-
#additional_data ⇒ Hash
readonly
Jwt additional data.
-
#app_id ⇒ String
readonly
Jwt application id.
-
#expires_at ⇒ Time
readonly
When Jwt will expire.
-
#identity ⇒ String
readonly
Jwt identity.
-
#issued_at ⇒ Time
readonly
When Jwt was issued.
-
#issuer ⇒ String
readonly
Jwt issuer.
-
#subject ⇒ String
readonly
Jwt subject.
Class Method Summary collapse
-
.restore_from_json(str_json) ⇒ JwtBodyContent
Restore body content from json.
Instance Method Summary collapse
-
#initialize(app_id:, identity:, issued_at:, expires_at:, data:) ⇒ JwtBodyContent
constructor
Initializes a new instance of the class.
-
#to_json ⇒ String
Json representation of body content.
Constructor Details
#initialize(app_id:, identity:, issued_at:, expires_at:, data:) ⇒ JwtBodyContent
Initializes a new instance of the class
76 77 78 79 80 81 82 83 84 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 76 def initialize(app_id:, identity:, issued_at:, expires_at:, data:) @app_id = app_id @identity = identity @issued_at = issued_at @expires_at = expires_at @additional_data = data @issuer = "#{SUBJECT_PREFIX}#{@app_id}" @subject = "#{IDENTITY_PREFIX}#{@identity}" end |
Instance Attribute Details
#additional_data ⇒ Hash (readonly)
Jwt additional data.
68 69 70 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 68 def additional_data @additional_data end |
#app_id ⇒ String (readonly)
Jwt application id.
44 45 46 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 44 def app_id @app_id end |
#expires_at ⇒ Time (readonly)
When Jwt will expire.
64 65 66 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 64 def expires_at @expires_at end |
#identity ⇒ String (readonly)
Jwt identity.
48 49 50 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 48 def identity @identity end |
#issued_at ⇒ Time (readonly)
When Jwt was issued.
60 61 62 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 60 def issued_at @issued_at end |
#issuer ⇒ String (readonly)
Jwt issuer.
52 53 54 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 52 def issuer @issuer end |
#subject ⇒ String (readonly)
Jwt subject.
56 57 58 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 56 def subject @subject end |
Class Method Details
.restore_from_json(str_json) ⇒ JwtBodyContent
Restore body content from json
100 101 102 103 104 105 106 107 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 100 def self.restore_from_json(str_json) model = JSON.parse(str_json) new(app_id: model['iss'].gsub(JwtBodyContent::SUBJECT_PREFIX, ''), identity: model['sub'].gsub(JwtBodyContent::IDENTITY_PREFIX, ''), issued_at: Time.at(model['iat']).utc, expires_at: Time.at(model['exp']).utc, data: model['ada']) end |
Instance Method Details
#to_json ⇒ String
Json representation of body content
88 89 90 91 92 93 94 95 96 |
# File 'lib/virgil/jwt/jwt_body_content.rb', line 88 def to_json model = { 'iss': issuer, 'sub': subject, 'iat': issued_at.to_i, 'exp': expires_at.to_i, 'ada': additional_data} model.to_json end |