Search code examples
ruby-on-railsoauthomniauthscopescoinbase-api

Applying additional oauth scopes in an omniauth initializer


I am trying to apply the coinbase wallet API with oauth to use its send functionality. I have been able to connect to the API and use its endpoints, but whenever I try to use the send functionality, I am thrown the error Invalid amount for meta[send_limit_amount]. My omniauth initializer looks like this:

provider :coinbase, , ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], 
scope: 'wallet:user:read wallet:user:email wallet:accounts:read wallet:transactions:send'

The reason for this error is because, in order to use the send functionality, coinbase requires additional parameter meta[send_limit_amount]. Where and how am I supposed to apply this additional scope?

UPDATE: So I've made some progress in that I am able to attach one meta scope to my initializer, which seems to be sticking (as shown when I print out the auth_info). This is the current state of my initializer:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :coinbase, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], scope: 'wallet:user:read wallet:user:email wallet:accounts:read ', :meta => {'send_limit_currency' => 'BTC'}
end

# wallet:transactions:send
# :meta => {'send_limit_amount' => '0.0001'}

The problem now is that I cannot seem to figure the syntax necessary to add the send_limit_amount property to the oauth meta hash.


Solution

  • Managed to solve the problem with the following initializer;

    Rails.application.config.middleware.use OmniAuth::Builder do
      provider :coinbase, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'],
      scope: 'wallet:user:read wallet:user:email wallet:accounts:read wallet:transactions:send',
      :meta => {'send_limit_amount' => 1}
    end
    

    Now, I need to either disable the two factor authentication or determine how to Re-play the request with CB-2FA-Token header