Class: Knocknock::AuthToken
- Inherits:
-
Object
- Object
- Knocknock::AuthToken
- Defined in:
- app/model/knocknock/auth_token.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
- #access_token ⇒ Object
-
#initialize(payload: {}, token: nil) ⇒ AuthToken
constructor
A new instance of AuthToken.
- #resource(resource_class) ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(payload: {}, token: nil) ⇒ AuthToken
Returns a new instance of AuthToken.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/model/knocknock/auth_token.rb', line 8 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, Knocknock.token_signature_algorithm end end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
6 7 8 |
# File 'app/model/knocknock/auth_token.rb', line 6 def payload @payload end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'app/model/knocknock/auth_token.rb', line 5 def token @token end |
Instance Method Details
#access_token ⇒ Object
20 21 22 |
# File 'app/model/knocknock/auth_token.rb', line 20 def access_token AccessToken.find_by(token: @payload['sub']) end |
#resource(resource_class) ⇒ Object
24 25 26 27 |
# File 'app/model/knocknock/auth_token.rb', line 24 def resource resource_class AccessToken.find_by(token: @payload['sub'], authenticatee_type: resource_class.to_s).authenticatee end |
#to_json(options = {}) ⇒ Object
29 30 31 |
# File 'app/model/knocknock/auth_token.rb', line 29 def to_json = {} { jwt: @token }.to_json end |