Class: Users::OmniauthCallbacksController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Defined in:
app/controllers/users/omniauth_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#openid_connect ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 6

def openid_connect
  @user = User.from_omniauth(request.env["omniauth.auth"])
  if @user.persisted?
    @user.add_role :administrator if User.with_role(:administrator).empty? # Create admin if there isn't one
     @user, event: :authentication # this will throw if @user is not activated
    set_flash_message(:notice, :success, kind: "OIDC") if is_navigational_format?
  else
    redirect_to new_user_session_url
    set_flash_message(:alert, :failure, kind: "OIDC", reason: @user.errors.full_messages.join("; ")) if is_navigational_format?
  end
rescue OmniAuth::Strategies::OpenIDConnect::CallbackError => error
  redirect_to new_user_session_url
  set_flash_message(:alert, :failure, kind: "OIDC", reason: error.error_reason) if is_navigational_format?
end