earthdata_token: Get NASA Earthdata bearer token

View source: R/auth.R

earthdata_tokenR Documentation

Get NASA Earthdata bearer token

Description

Returns the bearer token used for VIIRS/Black Marble downloads from NASA LAADS DAAC.

Usage

earthdata_token(token = NULL)

Arguments

token

Character string. If NULL, checks EARTHDATA_TOKEN env var, then tries EARTHDATA_USERNAME + EARTHDATA_PASSWORD.

Details

Getting a token (web):

  1. Create an account at https://urs.earthdata.nasa.gov

  2. Accept the MERIS and Sentinel EULAs under Profile > EULAs

  3. Go to Profile > Generate Token, click "Generate Token", then "Show Token"

  4. Copy the token (starts with ⁠EDL-⁠) and store it

Supplying the token:

  • Set EARTHDATA_TOKEN environment variable (recommended: add to ⁠~/.Renviron⁠)

  • Or pass it directly as the token argument

  • Or set EARTHDATA_USERNAME + EARTHDATA_PASSWORD to fetch it automatically

Bhuvan NTL functions (bhuvan_stats(), bhuvan_raster()) do not require any authentication.

Value

The access token string, invisibly.

Examples

## Not run: 
# Option 1: token from Profile > Generate Token on urs.earthdata.nasa.gov
Sys.setenv(EARTHDATA_TOKEN = "EDL-xxxxxxxxxxxxxxxxxxxx")
token <- earthdata_token()

# Option 2: username + password (fetches token automatically)
Sys.setenv(EARTHDATA_USERNAME = "myuser", EARTHDATA_PASSWORD = "mypass")
token <- earthdata_token()

# Option 3: pass directly
token <- earthdata_token("EDL-xxxxxxxxxxxxxxxxxxxx")

## End(Not run)

lightson documentation built on Nov. 3, 2026, 5:07 p.m.