gpt4 book ai didi

ruby-on-rails - Omniauth:如何在运行时设置身份验证提供程序详细信息

转载 作者:行者123 更新时间:2023-12-04 03:44:03 30 4
gpt4 key购买 nike

我有一个可从 2 个域访问的 rails 应用程序。 Facebook 要求我为每个域注册一个 facebook 应用程序,并为我提供每个域的凭据。使用 Omniauth,我只能指定一组在应用程序启动时设置的凭据。但是,我需要根据请求的主机为 FB 提供不同的凭据。

这里有2个问题:

  • 如何在运行时更改 facebook 的 Omniauth 凭据?
  • 如何拦截对 facebook 的调用,检查域并相应地设置凭据?前置过滤器将不起作用,因为 Omniauth 使用 Rack 中间件。

  • 任何建议都非常感谢!

    最佳答案

    从评论中复制答案以从“未回答”过滤器中删除此问题:

    I solved this myself now. The problem was that the fb strategy callsback to fb a second time to get an access token. In that second callthe wrong credentials were used (the ones set in the initializer). SoI had to patch the OAuth2 strategy so that it calls through to therails app again, to set the runtime credentials for that second call.In the call back, which normally only handles the response formOmniauth, I set the credentials and return a 404 unlessrequest.env["omniauth.auth"] is present. That works fine but has someside effects for apps without dynamic providers.

    The problem is now, that even if an application doesn't want to set the credentials at runtime, it has to add a condition to the callback like if request.env["omniauth.auth"] to avoid the callback code being executed when it is called the first time. The solution is probably to add a parameter to the Omniauth builder like :dynamic_provider and only call through to the app if it is set.


    ~ 每人回答 Nico

    关于ruby-on-rails - Omniauth:如何在运行时设置身份验证提供程序详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5007051/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com