Skip to content

Instantly share code, notes, and snippets.

@mardlin
Last active May 10, 2025 08:59
Show Gist options
  • Save mardlin/09cbf72586ea809a9129 to your computer and use it in GitHub Desktop.
Save mardlin/09cbf72586ea809a9129 to your computer and use it in GitHub Desktop.
A simple script for building a Coinbase Connect Authorization URL
/*
* A simple script for building an authorization redirect URL for your Coinbase Connect app.
* Follow the ##STEPS
*/
/* ##STEP1**: To generate an Authorization URI for a Sandbox App, set this to TRUE
* Hint: If you're using this script, you probably want to start on the Sandbox
*/
var useSandbox = true;
var productionAuthURI = 'https://www.coinbase.com/oauth/authorize/?',
sandboxAuthURI = 'https://sandbox.coinbase.com/oauth/authorize/?';
/* ##STEP2: get the client_id and redirect_uri from your OAuth app
/ at https://www.coinbase.com/settings/api or https://sandbox.coinbase.com/settings/api
*/
var appArgs = {
client_id : 'Your Client ID',
redirect_uri : 'Your redirect URI',
response_type : 'code' //don't change this
};
/* ##STEP3: Uncomment the permission scopes you need. Visit https://developers.coinbase.com/api/v2 to see the permissions
* required for each endpoint you plan to use.
*/
var scopes = [
// 'wallet:user:read',
// 'wallet:user:update',
// 'wallet:user:email',
// 'wallet:accounts:read',
// 'wallet:accounts:update',
// 'wallet:accounts:create',
// 'wallet:accounts:delete',
// 'wallet:payment-methods:read',
// 'wallet:payment-methods:delete',
// 'wallet:payment-methods:limits',
// 'wallet:transactions:read',
// 'wallet:transactions:send',
// 'wallet:transactions:request',
// 'wallet:transactions:transfer',
// 'wallet:buys:read',
// 'wallet:buys:create',
// 'wallet:sells:read',
// 'wallet:sells:create',
// 'wallet:addresses:read',
// 'wallet:addresses:create',
// 'wallet:orders:read',
// 'wallet:orders:create',
// 'wallet:orders:refund',
// 'wallet:checkouts:read',
// 'wallet:checkouts:create',
// 'wallet:deposits:read',
// 'wallet:deposits:create',
// 'wallet:withdrawals:read',
// 'wallet:withdrawals:create'
];
/* ## STEP4: If your scopes include 'wallet:transactions:send', you'll need to set these parameters
* Max is 100 USD per day. The less you ask, the more likely people with authorize your app.
* More info: https://developers.coinbase.com/docs/wallet/coinbase-connect/permissions#send-limits
*/
var metaArgs = {
send_limit_amount : 100,
send_limit_currency: 'USD',
send_limit_period: 'day'
};
// ##STEP5: Run ze file
function buildAuthURI( appArgs, metaArgs, scopes ){
//Sandbox or Production?
var authURI = productionAuthURI;
if ( useSandbox ){ authURI = sandboxAuthURI; }
// Convert the appArgs objects into a URI encoded query string
var queryParams = [];
for ( var param in appArgs ){
if ( appArgs.hasOwnProperty(param) ){
queryParams.push(encodeURIComponent( param ) + '=' + encodeURIComponent( appArgs[param] ));
}
}
// Do we need to include the send limits parameters in the query string?
if (scopes.indexOf('wallet:transactions:send') != -1){
for ( var param1 in metaArgs){
queryParams.push( 'meta[' + param1 + ']=' + metaArgs[param1] );
}
}
//Put it all together
authURI += queryParams.join('&') + '&scope=' + scopes.join(',');
return authURI;
}
console.log( buildAuthURI( appArgs, metaArgs, scopes ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment