简体   繁体   English

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

[英]What are callbacks doing in omniauth-facebook integration?

Documentation on omniauth-facebook mentions callbacks a lot, but I don't see callbacks inside the documentation, and I didn't need to write any callbacks (in the Javascript sense I'm used to) to make the authentication work. omniauth-facebook上的文档omniauth-facebook提到回调,但我在文档中没有看到回调,而且我不需要编写任何回调(在我习惯的 Javascript 意义上)来进行身份验证。

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

For example:例如:

By clicking on the above link, the user will be redirected to Facebook.通过点击上面的链接,用户将被重定向到 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" }

Callbacks Controller回调控制器

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

I don't see any explicitly written callbacks here so I assume there is something going on behind the scenes.我在这里没有看到任何明确编写的回调,所以我认为幕后发生了一些事情。

But I'm kind of confused - what are the callbacks actually doing and what part of this code is a callback?但我有点困惑 - 回调实际上在做什么,这段代码的哪一部分是回调?

Apologies in advance if this is a super newbie question.如果这是一个超级新手问题,请提前道歉。

A callback in OmniAuth is the return url where the user is redirected after authentication - its the endpoint where the external service calls your application back . OmniAuth 中的回调是用户在身份验证后重定向的返回 url - 它是外部服务回调您的应用程序的端点。 The term "callback" is quite frequently used this way when it comes to server side programming.在涉及服务器端编程时,术语“回调”经常以这种方式使用。

So in this case Users::OmniauthCallbacksController#facebook is the 'callback' handler for this authentication provider.因此,在这种情况下, Users::OmniauthCallbacksController#facebook是此身份验证提供程序的“回调”处理程序。

This is quite a different concept than the JavaScript concept of callbacks which is event oriented programming by passing functions around.这与 JavaScript 回调的概念完全不同,回调是通过传递函数进行面向事件的编程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM