Class: Devise::Api::Responses::TokenResponse
- Inherits:
-
Object
- Object
- Devise::Api::Responses::TokenResponse
- Defined in:
- lib/devise/api/responses/token_response.rb
Constant Summary collapse
- ACTIONS =
%i[ sign_in sign_up refresh revoke info ].freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#resource_owner ⇒ Object
readonly
Returns the value of attribute resource_owner.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #body ⇒ Object
- #default_body ⇒ Object
- #default_resource_owner ⇒ Object
-
#initialize(request, token:, action:) ⇒ TokenResponse
constructor
A new instance of TokenResponse.
- #status ⇒ Object
Constructor Details
#initialize(request, token:, action:) ⇒ TokenResponse
Returns a new instance of TokenResponse.
23 24 25 26 27 28 |
# File 'lib/devise/api/responses/token_response.rb', line 23 def initialize(request, token:, action:) @request = request @token = token @action = action @resource_owner = token&.resource_owner end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/devise/api/responses/token_response.rb', line 7 def action @action end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/devise/api/responses/token_response.rb', line 7 def request @request end |
#resource_owner ⇒ Object (readonly)
Returns the value of attribute resource_owner.
7 8 9 |
# File 'lib/devise/api/responses/token_response.rb', line 7 def resource_owner @resource_owner end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/devise/api/responses/token_response.rb', line 7 def token @token end |
Instance Method Details
#body ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/devise/api/responses/token_response.rb', line 30 def body return {} if revoke_action? return signed_up_body if sign_up_action? return info_body if info_action? default_body end |
#default_body ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/devise/api/responses/token_response.rb', line 38 def default_body { token: token.access_token, refresh_token: Devise.api.config.refresh_token.enabled ? token.refresh_token : nil, expires_in: token.expires_in, token_type: ::Devise.api.config..scheme, resource_owner: default_resource_owner }.compact end |
#default_resource_owner ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/devise/api/responses/token_response.rb', line 48 def default_resource_owner keys_to_extract = %i[id email created_at updated_at] if Devise.api.config.sign_up.extra_fields.present? keys_to_extract |= Devise.api.config.sign_up.extra_fields.map(&:to_sym) end resource_owner.slice(*keys_to_extract) end |
#status ⇒ Object
57 58 59 60 61 62 |
# File 'lib/devise/api/responses/token_response.rb', line 57 def status return :created if sign_up_action? return :no_content if revoke_action? :ok end |