Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在omniauth-facebook集成中回调做了什么?_Ruby On Rails_Callback_Omniauth - Fatal编程技术网

Ruby on rails 在omniauth-facebook集成中回调做了什么?

Ruby on rails 在omniauth-facebook集成中回调做了什么?,ruby-on-rails,callback,omniauth,Ruby On Rails,Callback,Omniauth,omniauth facebook上的文档提到了很多回调,但我在文档中没有看到回调,我也不需要编写任何回调(在Javascript的意义上,我已经习惯了)来实现身份验证 文件: 例如: 单击上面的链接,用户将被重定向到 脸谱网。(如果此链接不存在,请尝试重新启动服务器。) 插入他们的凭据后,他们将被重定向回 应用程序的回调方法 回调控制器 class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksControll

omniauth facebook
上的文档提到了很多回调,但我在文档中没有看到回调,我也不需要编写任何回调(在Javascript的意义上,我已经习惯了)来实现身份验证

文件:

例如:

单击上面的链接,用户将被重定向到 脸谱网。(如果此链接不存在,请尝试重新启动服务器。) 插入他们的凭据后,他们将被重定向回 应用程序的回调方法

回调控制器

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end
end
class Users::OmniAuthCallbackController:authentication#如果未激活@user,将引发此错误
如果是导航格式,设置flash消息(:notice,:success,:kind=>“Facebook”)?
其他的
会话[“designe.facebook_data”]=request.env[“omniauth.auth”]
将\重定向到新\用户\注册\ url
结束
结束
def故障
将\重定向到根\路径
结束
结束
我在这里没有看到任何显式编写的回调,所以我假设在幕后发生了一些事情

但我有点困惑——回调实际上在做什么,这段代码的哪一部分是回调


如果这是一个超级新手的问题,请提前道歉。

OmniAuth中的回调是在身份验证后重定向用户的返回url,它是外部服务回调应用程序的端点。当涉及到服务器端编程时,术语“回调”经常以这种方式使用

因此,在本例中,
Users::OmniAuthCallbackController#facebook
是此身份验证提供程序的“回调”处理程序


这与JavaScript回调概念完全不同,后者是通过传递函数进行面向事件编程。

回调处理程序
只是指重定向用户的代码部分?不,只是Facebook在授权对话框后重定向回的常规控制器动作。
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end
end