在
devise
消息来源,我找到了一个相当简单的解决方案。核心问题是如何
发明
使用相同的
omniauth
策略两次,但使用不同的API和回调URL。所以我们需要注册两个
omniauth-github
在两个不同的提供者ID下
和
名称。为了实现这一点,您需要在第二个实例化中显式地给出策略类名。所以,你会得到这样的结果:
# Github Enterprise login through standard github provider
config.omniauth :github,
Rails.configuration.ghe_oauth_id,
Rails.configuration.ghe_oauth_secret,
client_options: {
site: 'https://github-enterprise/api/v3',
authorize_url: 'https://github-enterprise/login/oauth/authorize',
token_url: 'https://github-enterprise/login/oauth/access_token'
},
scope: 'user repo'
# Github.com support using the same strategy, but with a different provider ID and name
config.omniauth :github_com,
Rails.configuration.github_com_oauth_id,
Rails.configuration.github_com_oauth_secret,
strategy_class: OmniAuth::Strategies::GitHub,
name: :github_com,
scope: 'user repo'
布线设置与使用单个
omniauth公司
提供商。在我的回调控制器中
发明
回调,我现在有了一个方法
github
用于通过Github Enterprise和one处理身份验证
github_com
对于github。com身份验证。