Class: JwtRest::Tokens::Jwt
- Inherits:
-
Object
- Object
- JwtRest::Tokens::Jwt
- Defined in:
- lib/jwt_rest/tokens/jwt.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(payload: nil, token: nil) ⇒ Jwt
constructor
A new instance of Jwt.
- #load_payload ⇒ Object
- #load_token ⇒ Object
Constructor Details
#initialize(payload: nil, token: nil) ⇒ Jwt
Returns a new instance of Jwt.
6 7 8 9 |
# File 'lib/jwt_rest/tokens/jwt.rb', line 6 def initialize(payload: nil, token: nil) @payload = payload || {} @token = token end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
4 5 6 |
# File 'lib/jwt_rest/tokens/jwt.rb', line 4 def payload @payload end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/jwt_rest/tokens/jwt.rb', line 4 def token @token end |
Instance Method Details
#load_payload ⇒ Object
11 12 13 14 15 |
# File 'lib/jwt_rest/tokens/jwt.rb', line 11 def load_payload @payload[:exp] = default_exp unless @payload[:exp] @token = JWT.encode(payload, key, 'RS384') self end |
#load_token ⇒ Object
17 18 19 20 21 |
# File 'lib/jwt_rest/tokens/jwt.rb', line 17 def load_token parts = JWT.decode(token, key.public_key, true, { algorithm: 'RS384' }) rescue nil @payload = parts.reduce({}, :merge) if parts self end |