Class: Nexmo::JWT
- Inherits:
-
Object
- Object
- Nexmo::JWT
- Defined in:
- lib/nexmo-jwt/jwt.rb,
lib/nexmo-jwt/version.rb
Constant Summary collapse
- VERSION =
'0.1.2'
Instance Attribute Summary collapse
-
#generator ⇒ Object
Returns the value of attribute generator.
-
#iat ⇒ Object
Returns the value of attribute iat.
-
#typ ⇒ Object
Returns the value of attribute typ.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(params = {}) ⇒ JWT
constructor
A new instance of JWT.
- #to_payload ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ JWT
Returns a new instance of JWT.
9 10 11 12 13 |
# File 'lib/nexmo-jwt/jwt.rb', line 9 def initialize(params = {}) @generator = params.fetch(:generator) @typ = params.fetch(:typ, 'JWT') @iat = params.fetch(:iat, Time.now.to_i) end |
Instance Attribute Details
#generator ⇒ Object
Returns the value of attribute generator.
7 8 9 |
# File 'lib/nexmo-jwt/jwt.rb', line 7 def generator @generator end |
#iat ⇒ Object
Returns the value of attribute iat.
7 8 9 |
# File 'lib/nexmo-jwt/jwt.rb', line 7 def iat @iat end |
#typ ⇒ Object
Returns the value of attribute typ.
7 8 9 |
# File 'lib/nexmo-jwt/jwt.rb', line 7 def typ @typ end |
Instance Method Details
#generate ⇒ Object
15 16 17 |
# File 'lib/nexmo-jwt/jwt.rb', line 15 def generate ::JWT.encode(to_payload, generator.private_key, generator.alg) end |
#to_payload ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nexmo-jwt/jwt.rb', line 19 def to_payload hash = { iat: iat, jti: generator.jti, exp: generator.exp || iat + generator.ttl, sub: generator.subject, application_id: generator.application_id, typ: typ } hash.merge!(generator.paths) if generator.paths hash.merge!(nbf: generator.nbf) if generator.nbf hash end |