如何更改 GoogleOauth2 omniauth 提供程序名称的名称?
How do you change the name of the GoogleOauth2 omniauth provider name?
我正在使用 Google Omniauth gem here and need to provide two instances of it so I can have them ask for a different set of permissions. I have this working with an equivalent Facebook gem using this guide。 Google gem 做同样的事情是行不通的。有谁知道我能做些什么来实现这一目标?
好的,我明白了。出于某种原因,Google Oauth2 gem 不适用于提供商名称作为符号,但会采用 class 名称。所以我可以用这个解决这个问题:
# initializers/omniauth.rb
module OmniAuth::Strategies
class GoogleIntegration < GoogleOauth2
end
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider OmniAuth::Strategies::GoogleIntegration, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
{
...
}
end
晚了几年,但现在是正确的做法:
Rails.application.config.middleware.use OmniAuth::Builder do
provider OmniAuth::Strategies::GoogleIntegration,
ENV["GOOGLE_CLIENT_ID"],
ENV["GOOGLE_CLIENT_SECRET"],
name: 'google_integration' # <=== Use the name option.
end
我正在使用 Google Omniauth gem here and need to provide two instances of it so I can have them ask for a different set of permissions. I have this working with an equivalent Facebook gem using this guide。 Google gem 做同样的事情是行不通的。有谁知道我能做些什么来实现这一目标?
好的,我明白了。出于某种原因,Google Oauth2 gem 不适用于提供商名称作为符号,但会采用 class 名称。所以我可以用这个解决这个问题:
# initializers/omniauth.rb
module OmniAuth::Strategies
class GoogleIntegration < GoogleOauth2
end
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider OmniAuth::Strategies::GoogleIntegration, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
{
...
}
end
晚了几年,但现在是正确的做法:
Rails.application.config.middleware.use OmniAuth::Builder do
provider OmniAuth::Strategies::GoogleIntegration,
ENV["GOOGLE_CLIENT_ID"],
ENV["GOOGLE_CLIENT_SECRET"],
name: 'google_integration' # <=== Use the name option.
end