Class: Knock::AuthToken
- Inherits:
-
Object
- Object
- Knock::AuthToken
- Defined in:
- app/model/knock/auth_token.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #current_user ⇒ Object
-
#initialize(payload: {}, token: nil) ⇒ AuthToken
constructor
A new instance of AuthToken.
Constructor Details
#initialize(payload: {}, token: nil) ⇒ AuthToken
Returns a new instance of AuthToken.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/model/knock/auth_token.rb', line 7 def initialize payload: {}, token: nil if token.present? @payload, _ = JWT.decode token, decode_key, true, @token = token else @payload = payload @token = JWT.encode claims.merge(payload), secret_key, Knock.token_signature_algorithm end end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'app/model/knock/auth_token.rb', line 5 def token @token end |
Instance Method Details
#current_user ⇒ Object
19 20 21 |
# File 'app/model/knock/auth_token.rb', line 19 def current_user @current_user ||= Knock.current_user_from_token.call @payload end |