【问题标题】:Rails omniauth-twitter dynamic client id and secretRails omniauth-twitter 动态客户端 ID 和密码
【发布时间】:2015-06-25 06:01:17
【问题描述】:

对于omniuath-twiiter,我想设置多个开发人员帐户但我无法在运行时设置环境变量

请帮忙

【问题讨论】:

    标签: ruby-on-rails omniauth clientid omniauth-twitter


    【解决方案1】:

    您可以将 id 和 secret 添加到配置文件中,例如 config.yml 并忽略 .gitignore 中的 config.yml ,跟踪 config.example.yml 文件以使每个开发人员都易于使用。

    omniauth:
       providers:
           - { name: 'google_oauth2', app_id: 'YOUR_APP_ID',
               app_secret: 'YOUR_APP_SECRET',
               args: { access_type: 'offline', approval_prompt: '' } }
           - { name: 'twitter', app_id: 'YOUR_APP_ID',
               app_secret: 'YOUR_APP_SECRET'}
    

    而配置omniuath-twiiter只需通过Settingslogicgem在config.yml中使用params,使用方便,将代码放入config/initializers/的文件中

    class Settings < Settingslogic
      source "#{Rails.root}/config/config.yml
      namespace Rails.env
    end
    
    module Foobar
      def self.config
        Settings
      end
    end
    

    然后像下面这样配置omniauth:

    Foobar.config.omniauth.providers.each do |provider|
       config.omniauth provider['name'].to_sym, provider['app_id'], provider['app_secret'], provider['args']
    end
    

    就是这样

    【讨论】:

    • 感谢您的回复。但我需要从数据库中调用 app_id 和 app_secret。实际上我需要多个 twiiter 开发人员帐户来管理同一个应用程序
    猜你喜欢
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 2012-11-04
    • 2018-06-27
    • 1970-01-01
    相关资源
    最近更新 更多