Class: Aven::Oauth::BaseController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Aven::Oauth::BaseController
- Defined in:
- app/controllers/aven/oauth/base_controller.rb
Direct Known Subclasses
Auth0Controller, EntraIdController, GithubController, GoogleController
Instance Method Summary collapse
-
#callback ⇒ Object
Handles OAuth callback.
-
#create ⇒ Object
Initiates OAuth flow.
-
#error ⇒ Object
Renders OAuth error page.
Methods inherited from ApplicationController
#current_workspace, #current_workspace=
Methods included from ApplicationHelper
#aven_importmap_tags, #view_component
Instance Method Details
#callback ⇒ Object
Handles OAuth callback
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 |
# File 'app/controllers/aven/oauth/base_controller.rb', line 17 def callback validate_state! token_data = exchange_code_for_token(params[:code]) user_info = fetch_user_info(token_data[:access_token]) user = find_or_create_user(user_info, token_data) if user.persisted? sign_in_and_redirect(user) else handle_failed_authentication(user) end rescue => e Rails.logger.error("OAuth authentication failed: #{e.class.name} - #{e.message}") Rails.logger.error(e.backtrace.first(10).join("\n")) unless Rails.env.production? = if Rails.env.production? "Authentication failed. Please try again." else "#{e.message}" end error_class = Rails.env.production? ? nil : e.class.name render_error_page(, error_class) end |
#create ⇒ Object
Initiates OAuth flow
9 10 11 12 13 14 |
# File 'app/controllers/aven/oauth/base_controller.rb', line 9 def create state = SecureRandom.hex(16) session[:oauth_state] = state redirect_to (state), allow_other_host: true end |
#error ⇒ Object
Renders OAuth error page
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/aven/oauth/base_controller.rb', line 45 def error = params[:message] || "Authentication failed" @error_class = params[:error_class] view_component( "oauth/error", error_message: , error_class: @error_class, current_user: ) end |