Class: DeviseToken::JsonWebToken
- Inherits:
-
Object
- Object
- DeviseToken::JsonWebToken
- Defined in:
- app/models/devise_token/json_web_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
- #current_resource(resource_class) ⇒ Object
-
#initialize(payload: {}, token: nil, verify_options: {}) ⇒ JsonWebToken
constructor
A new instance of JsonWebToken.
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(payload: {}, token: nil, verify_options: {}) ⇒ JsonWebToken
Returns a new instance of JsonWebToken.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/devise_token/json_web_token.rb', line 8 def initialize payload: {}, token: nil, verify_options: {} if token.present? @payload, _ = JWT.decode token.to_s, decode_key, true, .merge() @token = token else @payload = claims.merge(payload) @token = JWT.encode @payload, secret_key, DeviseToken.token_signature_algorithm end end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
6 7 8 |
# File 'app/models/devise_token/json_web_token.rb', line 6 def payload @payload end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'app/models/devise_token/json_web_token.rb', line 5 def token @token end |
Instance Method Details
#current_resource(resource_class) ⇒ Object
20 21 22 23 24 25 26 |
# File 'app/models/devise_token/json_web_token.rb', line 20 def current_resource resource_class if resource_class.respond_to? :auth_payload resource_class.auth_payload @payload else resource_class.find @payload['sub'] end end |
#to_json(options = {}) ⇒ Object
28 29 30 |
# File 'app/models/devise_token/json_web_token.rb', line 28 def to_json = {} {jwt: @token}.to_json end |