策略中的OmniAuth动态客户端选项站点 [英] OmniAuth dynamic client options site within the strategy

查看:87
本文介绍了策略中的OmniAuth动态客户端选项站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置为OAuth2提供程序的Rails应用程序(使用Doorkeeper).该应用程序每个用户帐户使用不同的子域(或通过cname记录使用完全不同的域)

I have a rails app set up as an OAuth2 provider (using Doorkeeper). The app uses a different subdomain per user account (or an entirely different domain through a cname record)

i.e. 
user1.myrailsapp.com
user2.myrailsapp.com
www.mycustomdomain.com

在提供者方面,一切都按预期进行.

On the provider side, everything is working as expected.

我还有第二个应用程序,它是使用第一个应用程序的公开API的客户端.我有一个可以使用的客户端版本,但是在OmniAuth策略中仅带有硬编码的网站网址.

I also have a second app that is a client making use of the first app's exposed API. I have a version of the client working but only with a hard coded site url in the OmniAuth strategy.

问题是,如何根据每个请求动态设置策略网址.

The question is, how can I dynamically set the strategy url on a per request basis.

推荐答案

对于感兴趣的任何人,解决方案都是使用动态提供程序: https://github.com/intridea/omniauth/wiki/动态提供程序

For anyone interested, the solution is in the use of dynamic providers: https://github.com/intridea/omniauth/wiki/Dynamic-Providers

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :mystrategy, ENV["OAUTH_ID"], ENV["OAUTH_SECRET"],
    :setup => lambda{|env| 
      env['omniauth.strategy'].options[:client_options].site = env['rack.session']['oauth_site']
    }
end

这篇关于策略中的OmniAuth动态客户端选项站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆