Class: Gdrivestrg::OmniauthCallbacksController

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

Instance Method Summary collapse

Instance Method Details

#google_oauth2Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/gdrivestrg/omniauth_callbacks_controller.rb', line 4

def google_oauth2
  # You need to implement the method below in your model (e.g. app/models/user.rb)
  @user = Kernel.const_get(Gdrivestrg.user_class).find_for_google_oauth2(request.env["omniauth.auth"], current_user)

  if @user.persisted?
  
    _params = {:user => @user, 
           :plugin_id => Cloudstrg::Cloudstrgplugin.find_by_plugin_name("gdrive"), 
           :redirect => "#{request.protocol}#{request.host_with_port}/users/auth/google_oauth2/callback", 
           :refresh_token => request.env["omniauth.auth"].credentials["refresh_token"], 
           :access_token => request.env["omniauth.auth"].credentials["token"], 
           :expires_in => request.env["omniauth.auth"].credentials["expires_at"], 
           :session => session}
    
    driver = CloudStrg.new_driver _params
    _session, url = driver.config _params
    session.merge!(_session)
    
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
     @user, :event => :authentication
  else
    session["devise.google_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end