Page 1 of 1

Bearer token API

Posted: Mon Sep 11, 2023 1:44 pm America/New_York
by alaroy
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.

Re: Bearer token API

Posted: Mon Sep 11, 2023 6:57 pm America/New_York
by NSIDCx - greckase
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.