Class: RailsSimpleAuth::OmniauthCallbacksController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/rails_simple_auth/omniauth_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/rails_simple_auth/omniauth_callbacks_controller.rb', line 8

def create
  auth_hash = request.env['omniauth.auth']
  provider = params[:provider]

  unless RailsSimpleAuth.configuration.oauth_provider_enabled?(provider)
    redirect_to new_session_path, alert: 'OAuth provider not enabled.'
    return
  end

  user = user_class.from_oauth(auth_hash)

  display_name = RailsSimpleAuth.configuration.oauth_provider_display_name(provider)

  if user&.persisted?
    (user, notice: "Signed in successfully with #{display_name}.")
  else
    redirect_to new_session_path, alert: "Could not authenticate with #{display_name}."
  end
end

#failureObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/rails_simple_auth/omniauth_callbacks_controller.rb', line 28

def failure
  error = request.env['omniauth.error']
  error_type = request.env['omniauth.error.type']
  strategy = request.env['omniauth.error.strategy']&.name

  Rails.logger.error(
    '[RailsSimpleAuth] OAuth failure: ' \
    "type=#{error_type.inspect}, " \
    "strategy=#{strategy.inspect}, " \
    "error=#{error&.message.inspect}"
  )

  redirect_to new_session_path, alert: 'Authentication failed. Please try again.'
end