Class: DeviseTokenAuth::OmniauthCallbacksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/devise_token_auth/omniauth_callbacks_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auth_paramsObject (readonly)

Returns the value of attribute auth_params.



4
5
6
# File 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb', line 4

def auth_params
  @auth_params
end

Instance Method Details

#omniauth_failureObject



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

def omniauth_failure
  @error = params[:message]
  render_data_or_redirect('authFailure', {error: @error})
end

#omniauth_successObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb', line 25

def omniauth_success
  get_resource_from_auth_hash
  create_token_info
  set_token_on_resource
  create_auth_params

  if resource_class.devise_modules.include?(:confirmable)
    # don't send confirmation email!!!
    @resource.skip_confirmation!
  end

  (:user, @resource, store: false, bypass: false)

  @resource.save!

  yield if block_given?

  render_data_or_redirect('deliverCredentials', @auth_params.as_json, @resource.as_json)
end

#redirect_callbacksObject

intermediary route for successful omniauth authentication. omniauth does not support multiple models, so we must resort to this terrible hack.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb', line 10

def redirect_callbacks

  # derive target redirect route from 'resource_class' param, which was set
  # before authentication.
  devise_mapping = request.env['omniauth.params']['resource_class'].underscore.gsub("/", "_").to_sym
  redirect_route = "#{request.protocol}#{request.host_with_port}/#{Devise.mappings[devise_mapping].fullpath}/#{params[:provider]}/callback"

  # preserve omniauth info for success route. ignore 'extra' in twitter
  # auth response to avoid CookieOverflow.
  session['dta.omniauth.auth'] = request.env['omniauth.auth'].except('extra')
  session['dta.omniauth.params'] = request.env['omniauth.params']

  redirect_to redirect_route
end