简体   繁体   English

通用的omniauth提供者/设计策略

[英]A generic omniauth provider/strategy for devise

I implemented an omniauth strategy as a gem but realized that it is just a basic implementation of the oauth. 我将omniauth策略实施为gem,但意识到这只是oauth的基本实现。

I configure in devise. 我设计中。 rb like this: rb是这样的:

config.omniauth :mystrategy, 'key', 'secret'

Is there an easier way to do this in devise without creating the gem, could I just configure it in a conifg block like 有没有一种更简单的方法可以在设计中执行此操作而不创建gem,我是否可以在一个conifg块中进行配置,例如

    config.omniauth :mystrategy do |strategy|
          strategy.key ='blah'
          strategy.authorize_path = 'blah'
    end

Can you show me an example or point me in the right direction? 你能给我一个例子或指出正确的方向吗? Everything I saw online was about building it as a strategy gem. 我在网上看到的所有内容都是关于将其构建为战略瑰宝的。

It sounds like you've written an oauth strategy from scratch and packaged it as a gem. 听起来您已经从头开始编写了oauth策略,并将其打包为gem。 If it's just an oauth or oauth2 strategy which you implemented entirely, I don't think you need to do that, or create a gem. 如果这只是您完全实现的oauth或oauth2策略,我认为您不需要这样做或创建一个gem。 However, I'm not sure there is any way to do it in just a config block. 但是,我不确定仅在config块中有任何方法可以做到这一点。 You should be able to do it by just using https://github.com/intridea/omniauth-oauth or https://github.com/intridea/omniauth-oauth2 and creating a subclass with a few methods as described in the READMEs. 您应该能够通过使用https://github.com/intridea/omniauth-oauthhttps://github.com/intridea/omniauth-oauth2并使用自述文件中描述的几种方法创建子类来做到这一点。

I haven't done this myself, but it's the approach taken by other omniauth strategies. 我自己还没有做过,但这是其他omniauth策略采用的方法。 For example, omniauth-twitter is based on the omniauth-oauth strategy as you can see by its superclass: 例如,omniauth-twitter基于omniauth-oauth策略,您可以通过其超类看到:

https://github.com/arunagw/omniauth-twitter/blob/master/lib/omniauth/strategies/twitter.rb https://github.com/arunagw/omniauth-twitter/blob/master/lib/omniauth/strategies/twitter.rb

omniauth-facebook is based on the omniauth-oauth2 strategy: omn​​iauth-facebook基于omniauth-oauth2策略:

https://github.com/mkdynamic/omniauth-facebook/blob/master/lib/omniauth/strategies/facebook.rb https://github.com/mkdynamic/omniauth-facebook/blob/master/lib/omniauth/strategies/facebook.rb

Just having your class defined in the Omniauth::Strategies namespace -- eg Omniauth::Strategies::Mystrategy should be enough for you to refer to it as :mystrategy in your omniauth config as mentioned under "Creating a Strategy" here: https://github.com/intridea/omniauth/wiki/Strategy-Contribution-Guide 只需在Omniauth :: Strategies命名空间中定义类-例如,Omniauth :: Strategies :: Mystrategy就足以让您在omniauth配置中将其称为:mystrategy,如此处“创建策略”中所述: https: //github.com/intridea/omniauth/wiki/Strategy-Contribution-Guide

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

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