Class: Compeon::Token::Base
- Inherits:
-
Object
- Object
- Compeon::Token::Base
- Defined in:
- lib/compeon/token/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#audience ⇒ Object
Returns the value of attribute audience.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#issued_at ⇒ Object
Returns the value of attribute issued_at.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#not_before ⇒ Object
Returns the value of attribute not_before.
-
#subject ⇒ Object
Returns the value of attribute subject.
Class Method Summary collapse
- .attributes ⇒ Object
- .decode(claim_verifications: {}, encoded_token:, key:) ⇒ Object
- .registered_claims_mapping ⇒ Object
Instance Method Summary collapse
- #attributes_valid? ⇒ Boolean
- #encode(key:) ⇒ Object
- #expires_at_valid? ⇒ Boolean
-
#initialize(audience: nil, expires_at: nil, issued_at: nil, issuer: nil, not_before: nil, subject: nil) ⇒ Base
constructor
A new instance of Base.
- #registered_claims ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(audience: nil, expires_at: nil, issued_at: nil, issuer: nil, not_before: nil, subject: nil) ⇒ Base
34 35 36 37 38 39 40 41 |
# File 'lib/compeon/token/base.rb', line 34 def initialize(audience: nil, expires_at: nil, issued_at: nil, issuer: nil, not_before: nil, subject: nil) @audience = audience @expires_at = expires_at @issued_at = issued_at @issuer = issuer @not_before = not_before @subject = subject end |
Instance Attribute Details
#audience ⇒ Object
Returns the value of attribute audience.
6 7 8 |
# File 'lib/compeon/token/base.rb', line 6 def audience @audience end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
6 7 8 |
# File 'lib/compeon/token/base.rb', line 6 def expires_at @expires_at end |
#issued_at ⇒ Object
Returns the value of attribute issued_at.
6 7 8 |
# File 'lib/compeon/token/base.rb', line 6 def issued_at @issued_at end |
#issuer ⇒ Object
Returns the value of attribute issuer.
6 7 8 |
# File 'lib/compeon/token/base.rb', line 6 def issuer @issuer end |
#not_before ⇒ Object
Returns the value of attribute not_before.
6 7 8 |
# File 'lib/compeon/token/base.rb', line 6 def not_before @not_before end |
#subject ⇒ Object
Returns the value of attribute subject.
6 7 8 |
# File 'lib/compeon/token/base.rb', line 6 def subject @subject end |
Class Method Details
.attributes ⇒ Object
9 10 11 |
# File 'lib/compeon/token/base.rb', line 9 def attributes @attributes ||= attributes_mapping.keys.freeze end |
.decode(claim_verifications: {}, encoded_token:, key:) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/compeon/token/base.rb', line 24 def decode(claim_verifications: {}, encoded_token:, key:) Compeon::Token::Decoder.new( claim_verifications: claim_verifications, encoded_token: encoded_token, key: key, token_klass: self ).decode end |
.registered_claims_mapping ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/compeon/token/base.rb', line 13 def registered_claims_mapping { audience: :aud, expires_at: :exp, issued_at: :iat, issuer: :iss, not_before: :nbf, subject: :sub }.freeze end |
Instance Method Details
#attributes_valid? ⇒ Boolean
67 68 69 |
# File 'lib/compeon/token/base.rb', line 67 def attributes_valid? self.class.attributes.none? { |accessor| public_send(accessor).nil? } end |
#encode(key:) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/compeon/token/base.rb', line 43 def encode(key:) Compeon::Token::Encoder.new( key: key, token: self ).encode end |
#expires_at_valid? ⇒ Boolean
63 64 65 |
# File 'lib/compeon/token/base.rb', line 63 def expires_at_valid? !expires_at.nil? && expires_at > Time.now.to_i end |
#registered_claims ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/compeon/token/base.rb', line 50 def registered_claims self .class .registered_claims_mapping .invert .transform_values { |claim| public_send(claim) } .compact end |
#valid? ⇒ Boolean
59 60 61 |
# File 'lib/compeon/token/base.rb', line 59 def valid? expires_at_valid? && attributes_valid? end |