【问题标题】:Ruby on Rails - Devise Omniauth - Coinbase Strategy - Pass account parameterRuby on Rails - 设计 Omniauth - Coinbase 策略 - 传递帐户参数
【发布时间】:2020-11-26 21:32:18
【问题描述】:

Coinbase Connect (OAuth2) 允许用户为特定帐户或用户拥有的所有帐户授予对应用程序的访问权限。

选择取决于 OAuth2 授权 URL 上的帐户参数(默认值 = select 以授予对单个帐户的访问权限)。

我需要使用account=all

有谁知道我可以在 Devise 哪里设置这个?

我试过了:

config/initializers/devise.rb:

config.omniauth :coinbase, ENV['COINBASE_CLIENT_ID'], ENV['COINBASE_SECRET_ID'], scope: 'wallet:user:email wallet:accounts:read wallet:payment-methods:read wallet:sells:create wallet:withdrawals:create', account: :all

但这并没有改变授权 URL

然后我尝试在app/views/pages/profile.html.erb的omniauth_authorize_path中添加参数

        <button class="d-flex justify-content-between align-items-center pr-4 coinbase-btn">
          <%= image_tag 'logo-coinbase-white.svg', class: "coinbase-logo" %>
          <%- User.omniauth_providers.each do |provider| %>
            <%= link_to "Connect your #{OmniAuth::Utils.camelize(provider)} Wallet",
            omniauth_authorize_path(current_user, provider, account: 'all') %>
          <% end %>
        </button>

(这是我希望用户将他们的 coinbase 帐户与他们在我的应用程序上的帐户相关联的页面)

【问题讨论】:

    标签: ruby-on-rails devise omniauth coinbase-api


    【解决方案1】:

    查看我正在使用的 omniauth-coinbase gem,我发现我们可以传递的选项列表在第 30 行定义为 here

    第 30 行:option :authorize_options, [:scope, :meta]

    这一行指定我们可以使用哪些选项。

    因此我分叉了 gem 并将 :account 添加到授权选项列表中

    然后我可以在我的devise.rb 中传递它

    config.omniauth :coinbase, 
                    ENV['COINBASE_CLIENT_ID'],
                    ENV['COINBASE_SECRET_ID'],
                    scope: 'wallet:user:email wallet:accounts:read wallet:payment-methods:read wallet:sells:create wallet:withdrawals:create',
                    account: 'all'
    

    【讨论】:

      猜你喜欢
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 2014-02-14
      • 2017-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多