Module: YallaAuthRubyClient::ControllerAuthentication
- Defined in:
- lib/yalla_auth_ruby_client/controller_authentication.rb
Instance Method Summary collapse
- #auth_token_cookie ⇒ Object
- #authenticate_user ⇒ Object
- #authenticate_user! ⇒ Object
- #current_user ⇒ Object
- #logout ⇒ Object
Instance Method Details
#auth_token_cookie ⇒ Object
8 9 10 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 8 def .signed[:auth_token] end |
#authenticate_user ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 12 def authenticate_user 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) (@current_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
36 37 38 39 40 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 36 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
42 43 44 |
# File 'lib/yalla_auth_ruby_client/controller_authentication.rb', line 42 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 |