Class: Devise::Api::TokensController
- Inherits:
-
Object
- Object
- Devise::Api::TokensController
- Defined in:
- app/controllers/devise/api/tokens_controller.rb
Instance Method Summary collapse
-
#info ⇒ Object
rubocop:enable Metrics/AbcSize.
-
#refresh ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#revoke ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#sign_in ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#sign_up ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#info ⇒ Object
rubocop:enable Metrics/AbcSize
75 76 77 78 79 80 |
# File 'app/controllers/devise/api/tokens_controller.rb', line 75 def info token_response = Devise::Api::Responses::TokenResponse.new(request, token: current_devise_api_token, action: __method__) render json: token_response.body, status: token_response.status end |
#refresh ⇒ Object
rubocop:disable Metrics/AbcSize
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/controllers/devise/api/tokens_controller.rb', line 106 def refresh unless Devise.api.config.refresh_token.enabled error_response = Devise::Api::Responses::ErrorResponse.new(request, resource_class: resource_class, error: :refresh_token_disabled) return render json: error_response.body, status: error_response.status end if current_devise_api_refresh_token.blank? error_response = Devise::Api::Responses::ErrorResponse.new(request, error: :invalid_token, resource_class: resource_class) return render json: error_response.body, status: error_response.status end if current_devise_api_refresh_token.revoked? error_response = Devise::Api::Responses::ErrorResponse.new(request, error: :revoked_token, resource_class: resource_class) return render json: error_response.body, status: error_response.status end Devise.api.config.before_refresh.call(current_devise_api_refresh_token, request) service = Devise::Api::TokensService::Refresh.new(devise_api_token: current_devise_api_refresh_token).call if service.success? token_response = Devise::Api::Responses::TokenResponse.new(request, token: service.success, action: __method__) Devise.api.config.after_successful_refresh.call(service.success.resource_owner, service.success, request) return render json: token_response.body, status: token_response.status end error_response = Devise::Api::Responses::ErrorResponse.new(request, resource_class: resource_class, **service.failure) render json: error_response.body, status: error_response.status end |
#revoke ⇒ Object
rubocop:disable Metrics/AbcSize
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/devise/api/tokens_controller.rb', line 83 def revoke Devise.api.config.before_revoke.call(current_devise_api_token, request) service = Devise::Api::TokensService::Revoke.new(devise_api_token: current_devise_api_token).call if service.success? token_response = Devise::Api::Responses::TokenResponse.new(request, token: service.success, action: __method__) Devise.api.config.after_successful_revoke.call(service.success&.resource_owner, service.success, request) return render json: token_response.body, status: token_response.status end error_response = Devise::Api::Responses::ErrorResponse.new(request, resource_class: resource_class, **service.failure) render json: error_response.body, status: error_response.status end |
#sign_in ⇒ Object
rubocop:disable Metrics/AbcSize
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/devise/api/tokens_controller.rb', line 48 def sign_in Devise.api.config.before_sign_in.call(sign_in_params, request, resource_class) service = Devise::Api::ResourceOwnerService::SignIn.new(params: sign_in_params, resource_class: resource_class).call if service.success? token = service.success call_devise_trackable!(token.resource_owner) token_response = Devise::Api::Responses::TokenResponse.new(request, token: service.success, action: __method__) Devise.api.config.after_successful_sign_in.call(token.resource_owner, token, request) return render json: token_response.body, status: token_response.status end error_response = Devise::Api::Responses::ErrorResponse.new(request, resource_class: resource_class, **service.failure) render json: error_response.body, status: error_response.status end |
#sign_up ⇒ Object
rubocop:disable Metrics/AbcSize
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/devise/api/tokens_controller.rb', line 14 def sign_up unless Devise.api.config.sign_up.enabled error_response = Devise::Api::Responses::ErrorResponse.new(request, error: :sign_up_disabled, resource_class: resource_class) return render json: error_response.body, status: error_response.status end Devise.api.config.before_sign_up.call(sign_up_params, request, resource_class) service = Devise::Api::ResourceOwnerService::SignUp.new(params: sign_up_params, resource_class: resource_class).call if service.success? token = service.success call_devise_trackable!(token.resource_owner) token_response = Devise::Api::Responses::TokenResponse.new(request, token: token, action: __method__) Devise.api.config.after_successful_sign_up.call(token.resource_owner, token, request) return render json: token_response.body, status: token_response.status end error_response = Devise::Api::Responses::ErrorResponse.new(request, resource_class: resource_class, **service.failure) render json: error_response.body, status: error_response.status end |