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
14 15 16 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 14 def authenticate_user raise AuthenticationError, "Authentication required" unless current_user end |
#authenticate_user! ⇒ Object
18 19 20 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 18 def authenticate_user! raise AuthenticationError, "Authentication required" unless current_user end |
#current_user ⇒ Object
10 11 12 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 10 def current_user @current_user ||= authenticate_from_token end |
#refresh_token ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 35 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
22 23 24 25 26 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 22 def sign_in(user, request) tokens = user.generate_auth_tokens(request) @current_user = user tokens end |
#sign_out ⇒ Object
28 29 30 31 32 33 |
# File 'app/controllers/concerns/dscf/core/authenticatable.rb', line 28 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 |