Ruby on Rails - 设计 Omniauth - Coinbase 策略 - 传递账户参数

Ruby on Rails - Devise Omniauth - Coinbase Strategy - Pass account parameter

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>

(这是我希望用户 link 他们的 coinbase 帐户和他们在我的应用程序上的帐户的页面)

查看我正在使用的 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'