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

#failureObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 33

def failure
  client_errors = [
    "#<AttrRequired::AttrMissing: 'identifier' required.>",
    "#<Rack::OAuth2::Client::Error: invalid_client>",
  ]
  if client_errors.include?(request.env['omniauth.error'].inspect)
    render
  else
    redirect_to root_path
  end
end

#passthruObject



45
46
47
# File 'app/controllers/users/omniauth_callbacks_controller.rb', line 45

def passthru
  redirect_to root_path
end

#strongmindObject



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

def strongmind
  auth = request.env['omniauth.auth']
  Rails.logger.info "[DEBUG] OAUTH CALLBACK - User: #{@user&.id}, Auth: #{auth.inspect}"
  User.auth_token_cache = auth
  @user = User.with_credentials(auth)

  render plain: "You do not have permission to access this application.", status: :unauthorized and return if @user.nil?

if auth.credentials['refresh_token'].blank?
  Rails.logger.error "[DEBUG] OAUTH MISSING REFRESH TOKEN - User: #{@user&.id}"
end

reset_session
session[:refresh_token] = auth.credentials['refresh_token']
  
  flash.delete(:notice)

  if @user.persisted?
     @user, event: :authentication # this will throw if @user is not activated
  else
    session['devise.openid_connect_data'] = { uid: @user.uid } # Removing extra as it can overflow some session stores
     @user
  end
end