Module: Dscf::Core::Authenticatable
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/dscf/core/authenticatable.rb
Instance Method Summary collapse
- #authenticate_user ⇒ Object
- #authenticate_user! ⇒ Object
- #current_user ⇒ Object
- #refresh_token ⇒ Object
- #sign_in(user, request) ⇒ Object
- #sign_out ⇒ Object
Instance Method Details
#authenticate_user ⇒ Object
19 20 21 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 19 def authenticate_user authenticate_user! if authentication_required? end |
#authenticate_user! ⇒ Object
15 16 17 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 15 def authenticate_user! raise AuthenticationError, "Authentication required" unless current_user end |
#current_user ⇒ Object
11 12 13 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 11 def current_user @current_user ||= authenticate_from_token end |
#refresh_token ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 36 def refresh_token refresh_token_value = extract_refresh_token_from_params return nil unless refresh_token_value begin AuthService.refresh_access_token(refresh_token_value, request) rescue AuthenticationError nil end end |
#sign_in(user, request) ⇒ Object
23 24 25 26 27 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 23 def sign_in(user, request) tokens = user.generate_auth_tokens(request) @current_user = user tokens end |
#sign_out ⇒ Object
29 30 31 32 33 34 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 29 def sign_out # Revoke the current refresh token if available refresh_token_value = extract_refresh_token_from_params AuthService.revoke_refresh_token(refresh_token_value) if refresh_token_value @current_user = nil end |