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

What are callbacks doing in omniauth-facebook integration?

关于 omniauth-facebook 的文档提到了很多回调,但我没有在文档中看到回调,而且我不需要编写任何回调(在 Javascript 意义上我是用于)使身份验证工作。

文档:https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

例如:

By clicking on the above link, the user will be redirected to Facebook. (If this link doesn't exist, try restarting the server.) After inserting their credentials, they will be redirected back to your application's callback method.

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

回调控制器

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

我在这里没有看到任何明确编写的回调,所以我假设幕后发生了一些事情。

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

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

OmniAuth 中的回调是 return url 用户在身份验证后被重定向的位置 - 它是外部服务 回调您的应用程序的端点 .在服务器端编程中,术语 "callback" 经常以这种方式使用。

所以在这种情况下 Users::OmniauthCallbacksController#facebook 是此身份验证提供程序的 'callback' 处理程序。

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