Method: ActionDispatch::Routing::Mapper#devise_omniauth_callback

Defined in:
lib/devise/rails/routes.rb

#devise_omniauth_callback(mapping, controllers) ⇒ Object (protected)

:nodoc:



420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/devise/rails/routes.rb', line 420

def devise_omniauth_callback(mapping, controllers) #:nodoc:
  if mapping.fullpath =~ /:[a-zA-Z_]/
    raise <<-ERROR
Devise does not support scoping OmniAuth callbacks under a dynamic segment
and you have set #{mapping.fullpath.inspect}. You can work around by passing
`skip: :omniauth_callbacks` to the `devise_for` call and extract omniauth
options to another `devise_for` call outside the scope. Here is an example:

    devise_for :users, only: :omniauth_callbacks, controllers: {omniauth_callbacks: 'users/omniauth_callbacks'}

    scope '/(:locale)', locale: /ru|en/ do
devise_for :users, skip: :omniauth_callbacks
    end
ERROR
  end
  current_scope = @scope.dup
  if @scope.respond_to? :new
    @scope = @scope.new path: nil
  else
    @scope[:path] = nil
  end
  path_prefix = Devise.omniauth_path_prefix || "/#{mapping.fullpath}/auth".squeeze("/")

  set_omniauth_path_prefix!(path_prefix)

  mapping.to.omniauth_providers.each do |provider|
    match "#{path_prefix}/#{provider}",
      to: "#{controllers[:omniauth_callbacks]}#passthru",
      as: "#{provider}_omniauth_authorize",
      via: OmniAuth.config.allowed_request_methods

    match "#{path_prefix}/#{provider}/callback",
      to: "#{controllers[:omniauth_callbacks]}##{provider}",
      as: "#{provider}_omniauth_callback",
      via: [:get, :post]
  end
ensure
  @scope = current_scope
end