Skip to main content

Authenticate to the API: JWTs

API: Drive

This doc covers the Drive API. If you're using the Drive (classic) API, see the how-to guide for Drive (classic) JWTs.

Prerequisites​

Before getting started, ensure you have created and saved an access key from the Developer Portal.

To continue, you will need: developer_id, key_id and signing_secret

Install a JWT library​

Most programming languages provide support for creating JSON Web Tokens (JWTs) either directly in the language or as a package. Select your language and then follow the instructions to install the package, if needed.

Open a terminal and navigate to your project directory, then run:

npm install jsonwebtoken

Generate a JWT​

JWTs are created using an access key. Use these code snippets to generate a correctly-formatted JWT from your access key.

Copy the code snippet below into your project file. Replace PASTE_YOUR_ACCESS_KEY_HERE with your access key.

const jwt = require('jsonwebtoken')

const accessKey = PASTE_YOUR_ACCESS_KEY_HERE

const data = {
aud: 'doordash',
iss: accessKey.developer_id,
kid: accessKey.key_id,
exp: Math.floor(Date.now() / 1000 + 300),
iat: Math.floor(Date.now() / 1000),
}

const headers = { algorithm: 'HS256', header: { 'dd-ver': 'DD-JWT-V1' } }

const token = jwt.sign(
data,
Buffer.from(accessKey.signing_secret, 'base64'),
headers,
)

console.log(token)

Then, test your code. In your terminal, run:

node app.js

If you were successful, you should see output like this:

A screenshot of a terminal showing a successful run of the program