Bearer token API

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
alaroy
Posts: 78
Joined: Tue Nov 21, 2006 3:33 pm America/New_York
Answers: 0

Bearer token API

by alaroy » Mon Sep 11, 2023 1:44 pm America/New_York

I noticed that an API has been set up for managing earth data bearer tokens which is described here:

https://urs.earthdata.nasa.gov/documentation/for_users/user_token

I'm having trouble getting the /api/users/tokens request to work even when using credentials that work fine when I log into earthdata:

curl --request GET --url https://uat.urs.earthdata.nasa.gov/api/users/tokens --header 'Authorization: Basic alaroy:my-password'

returns

Invalid credentials

Any idea what I'm doing wrong, please?

Also - Has anybody published scripts that will automatically update your token? I'd prefer to not have inherently unreliable humans (like myself) remembering to do it every 90 days...

-Andrew L.

Tags:

NSIDC - greckase
User Services
User Services
Posts: 12
Joined: Tue Jan 25, 2022 11:32 am America/New_York
Answers: 0

Re: Bearer token API

by NSIDC - greckase » Mon Sep 11, 2023 6:57 pm America/New_York

Dear Colleague,

Thank you for posting your question.
First, there is a typo in the command on that webpage (https://urs.earthdata.nasa.gov/documentation/for_users/user_token). The command for getting the bearer token programmatically: curl --request GET \ --url https://uat.urs.earthdata.nasa.gov/api/users/tokens \ --header 'Authorization: Basic username:userpassword' should not contain "uat" after the "https://" in the url. UAT is the NASA test environment.
So the command used should be:
curl --request GET \ --url https://urs.earthdata.nasa.gov/api/users/tokens \ --header 'Authorization: Basic username:userpassword'

Secondly, the username:userpassword string needs to be encoded into base64.

I am not aware of any scripts currently built to automatically generate new tokens every 90 days.

Post Reply