Module: YallaAuthRubyClient::ControllerAuthentication
- Defined in:
- lib/yalla_auth_ruby_client/controller_authentication.rb
Instance Method Summary collapse
Instance Method Details
#authenticate_user ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 8 def authenticate_user token = .signed[:auth_token] return false unless token.present? begin api_client = OpenapiClient::AuthApi.new response = api_client.auth_validate_token_get(token) if response && response.success @yalla_user = response.user @current_user = find_or_create_app_user(@yalla_user) true else .delete(:auth_token) false end rescue OpenapiClient::ApiError => e Rails.logger.error "Authentication failed: #{e.message}" .delete(:auth_token) false end end |
#authenticate_user! ⇒ Object
31 32 33 34 35 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 31 def authenticate_user! return if authenticate_user redirect_to "#{ENV['AUTH_URL']}/users/sign_in?redirect_uri=#{request.original_url}", allow_other_host: true end |
#current_user ⇒ Object
37 38 39 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 37 def current_user @current_user end |
#logout ⇒ Object
3 4 5 6 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 3 def logout .delete(:auth_token, httponly: true) redirect_to ENV["AUTH_URL"], allow_other_host: true end |