Sign In With Coinbase API Key Authentication | Coinbase Cloud (2024)

API Key authentication should only be used to access your own account. To securely access the accounts of other Coinbase users, use Sign in with Coinbase (OAuth2)

info

Use Sign in with Coinbase (OAuth2) to securely access other Coinbase users' accounts.

Signing Requests

API key authentication requires each request to be signed (as an enhanced security measure).

Generating an API Key

You can create and activate new API keys in your API settings. Your API keys should be assigned to access only accounts and permission scopes that are necessary for your app to function.

Making a Request

All REST requests must contain the following headers:

  • CB-ACCESS-KEY API key as a string
  • CB-ACCESS-SIGN Message signature (see below)
  • CB-ACCESS-TIMESTAMP Timestamp for your request

All request bodies should have content type application/json and be valid JSON.

Example request:

curl https://api.coinbase.com/v2/user \
--header "CB-ACCESS-KEY: <your api key>" \
--header "CB-ACCESS-SIGN: <the user generated message signature>" \
--header "CB-ACCESS-TIMESTAMP: <a timestamp for your request>"

Selecting a Timestamp

The CB-ACCESS-TIMESTAMP header MUST be number of seconds since Unix Epoch in UTC.

Your timestamp must be within 30 seconds of the API service time, or your request will be considered expired and rejected. If you think there is a time skew between your server and the API servers, use the time API endpoint to query for the API server time.

Creating a Signature

The CB-ACCESS-SIGN header is generated by creating a sha256 HMAC using the secret key on the prehash string timestamp + method + requestPath + body (where + represents string concatenation).

  • timestamp is the same as the X-CB-ACCESS-TIMESTAMP header.

  • method should be UPPER CASE.

  • requestPath is the full path and query parameters of the URL, e.g.: /v2/exchange-rates?currency=USD.

  • body is the request body string. It is omitted if there is no request body (typically for GET requests).

Signature Examples

The following examples demonstrate how to generate a signature:

  • Python
  • Ruby
  • JavaScript
# Requires python-requests. Install with pip or easy-install
## Install with pip: pip install requests
## Install with easy-install: easy_install requests

import json, hmac, hashlib, time, requests
from requests.auth import AuthBase

# Before implementation, set environmental variables with the names API_KEY and API_SECRET
API_KEY = 'API_KEY'
API_SECRET = 'API_SECRET'

# Create custom authentication for Coinbase API
class CoinbaseWalletAuth(AuthBase):
def __init__(self, api_key, secret_key):
self.api_key = api_key
self.secret_key = secret_key

def __call__(self, request):
timestamp = str(int(time.time()))
message = timestamp + request.method + request.path_url + (request.body or '')
signature = hmac.new(self.secret_key.encode(), message.encode(), hashlib.sha256).hexdigest()

request.headers.update({
'CB-ACCESS-SIGN': signature,
'CB-ACCESS-TIMESTAMP': timestamp,
'CB-ACCESS-KEY': self.api_key,
})
return request

api_url = 'https://api.coinbase.com/v2/'
auth = CoinbaseWalletAuth(API_KEY, API_SECRET)

# Get current user
r = requests.get(api_url + 'user', auth=auth)
print r.json()
# {u'data': {u'username': None, u'resource': u'user', u'name': u'User'...

# Send funds
tx = {
'type': 'send',
'to': 'user@example.com',
'amount': '10.0',
'currency': 'USD',
}
r = requests.post(api_url + 'accounts/primary/transactions', json=tx, auth=auth)
print r.json()
# {u'data': {u'status': u'pending', u'amount': {u'currency': u'BTC'...

Security Best Practices

Storing Credentials Securely

Store your credentials securely. If someone obtains your api_secret with the wallet:transactions:send permission, they will be able to send all the digital currency out of your account.

Avoid storing API keys in your code base (which gets added to version control). The recommended best practice is to store them in environment variables. Learn more about environment variables here. Separating credentials from your code base and database is always good practice.

API Key access is turned off by default on all accounts. To implement an API Key integration, you therefore must first enable it,and then take necessary precautions to store the API Key securely. You can always regenerate your API Key (or disable it) if you feel it has been compromised.

Validating SSL Certificates

It is also very important that your application validates our SSL certificate when it connects over https. This helps prevent a man in the middle attack. If you are using a client library, this may be turned on by default, but you should confirm this. Whenever you see 'verify SSL' you should always ensure it is set to true.

Additional Security for API Keys

For enhanced API Key security, we recommend that you whitelist IP addresses that are permitted to make requests with a particular API Key.

You can specify IP addresses to whitelist when creating a new API Key or editing an existing one.

Was this helpful?

Sign In With Coinbase API Key Authentication | Coinbase Cloud (2024)

FAQs

How do I authenticate Coinbase API? ›

CDP API keys​
  1. Log into Coinbase Developer Platform (CDP).
  2. Navigate to Access → API keys.
  3. In the Create API key dialog, configure: ...
  4. Click Create & Download.
  5. Click Complete 2-factor authentication and enter your CDP 2FA code.
7 days ago

How do I use my Coinbase API key? ›

How to Set up Your Coinbase API Keys (Steps):
  1. Step 1: Create Your Keys. 1.1 Sign in to your Coinbase account, click on your profile in the top right corner, then click on “Settings” ...
  2. Step 2: Configure API Settings. ...
  3. Step 3: Wait 48 Hours. ...
  4. Step 4: Link Your Keys to Crypto Pro.

What is the API key secret passphrase in Coinbase? ›

Generating an API Key​

When creating a key, you must remember (and should write down) your (1) key, (2) secret, and (3) passphrase. The key and secret are randomly generated and provided by Coinbase Exchange -- you choose a passphrase to further secure your API access.

Why is my API key disabled in Coinbase? ›

Note: For some Coinbase accounts, Coinbase will keep new API keys disabled for 48 hours from their creation, for security purposes. If this is the case for your account, you should get an email and/or text message alerting you to this.

How do I authenticate my API? ›

Authentication is typically done by requiring the client to provide some form of credentials – such as a user name and password, an OAuth token, or a JSON Web Token (JWT). As an API owner, you can implement authentication in Apigee using policies.

Where do I get my Coinbase API key? ›

Sign in to your account and access your Settings by selecting the profile menu in your account and choosing Settings from the drop-down menu. Select the Security tab to view your current API keys and select New API key to generate a new key. This should appear under your existing API Keys automatically.

What does API key mean on Coinbase? ›

An API Key can be considered as a username that is generating to allow access to data. In this example, the Coinbase Pro API is generated by the exchange and you then pass it on to another application. The application will then import your data based on the permissions you allow for.

What is an API key and how does it work? ›

API Keys Definition and Meaning

An application programming interface (API) key is a code used to identify and authenticate an application or user. API keys are available through platforms, such as a white-labeled internal marketplace.

What is Coinbase Cloud? ›

Coinbase Cloud is a platform with blockchain infrastructure for building crypto projects with products like Wallet as a Service. You'll start your WaaS journey in Cloud when you create your first API key pair under Settings > API management.

How do I create an API passphrase in Coinbase? ›

How to create an API key
  1. Select API in the left navigation bar of the screen and select Create API Key.
  2. Enter your API key name, select the appropriate permission, create a passphrase, and enter the IP addresses that will be used to connect to the FIX and REST APIs and select Generate API Key.

How do I find my API secret key? ›

The API secret key is used to identify your account. You will be asked to provide one to connect to some of our services like the Google Sheets Add-on and the API functionalities. You can find your API secret key in the API page on your dashboard. You can also create new API keys in the same section if necessary.

What is my Coinbase secret key? ›

When you first buy cryptocurrency, you are issued two keys: a public key, which works like an email address (meaning you can safely share it with others, allowing you to send or receive funds), and a private key, which is typically a string of letters and numbers (and which is not to be shared with anyone).

Why is my API key not working? ›

Ensure that your public and private keys are entered in their correct fields. There are instances where a public key was used instead of a private key, and vice-versa. One pair of API keys won't work on multiple sites. If you have multiple sites, make sure each site has the correct pair of API keys.

Why my API key is invalid? ›

API keys can be revoked for a variety of reasons, such as if they are compromised or if they are no longer needed. If your API key has been revoked, you will need to create a new API key. There might be a problem with the Google Cloud Vision API.

How do I enable API key? ›

Enabling an API
  1. In the Google Cloud console, go to APIs & services for your project. Go to APIs & Services.
  2. On the Library page, click Private APIs. ...
  3. Click the API you want to enable. ...
  4. In the page that displays information about the API, click Enable.

How do I set up Coinbase API? ›

Creating API Keys​
  1. Log into Coinbase Developer Platform (CDP).
  2. Navigate to Access → API keys.
  3. In the Create API key dialog, configure: ...
  4. Click Create & Download.
  5. Click Complete 2-factor authentication and enter your CDP 2FA code.
Apr 19, 2024

What are the authentication methods for Coinbase? ›

Coinbase supports the following types, listed from most to least secure.
  • Security Key. This is a physical hardware authentication device that generates a one-time-password. ...
  • Passkey. ...
  • Authenticator (TOTP) app. ...
  • Coinbase Security Prompt. ...
  • SMS/Text.

Top Articles
Latest Posts
Article information

Author: Duane Harber

Last Updated:

Views: 6330

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Duane Harber

Birthday: 1999-10-17

Address: Apt. 404 9899 Magnolia Roads, Port Royceville, ID 78186

Phone: +186911129794335

Job: Human Hospitality Planner

Hobby: Listening to music, Orienteering, Knapping, Dance, Mountain biking, Fishing, Pottery

Introduction: My name is Duane Harber, I am a modern, clever, handsome, fair, agreeable, inexpensive, beautiful person who loves writing and wants to share my knowledge and understanding with you.