earthaccess icon indicating copy to clipboard operation
earthaccess copied to clipboard

Persisting credentials to netrc fails if we try to login first

Open betolink opened this issue 2 years ago • 3 comments

@eeholmes ran into this on a workshop using earthaccess, if we try to login first and then persist credentials earthaccess will authenticate and won't trigger the persistence.

import earthaccess

auth = earthaccess.login()

if not auth.authenticated:
    # won't persist the credentials
    earthaccess.login(strategy="interactive", persist=True)

however this works just fine:

import earthaccess

earthaccess.login(strategy="interactive", persist=True)

Proposal:

We need to ask users if they want to persist their credentials when we ask for them, then we'll only need earthaccess.login() everywhere and user's don't need to know about Persist=True

betolink avatar Sep 12 '23 03:09 betolink

@betolink Is this something you would still like to pursue? Or OBE?

asteiker avatar Oct 29 '24 18:10 asteiker

I just ran into this issue. Thanks for pointing this out @betolink. As a new user this was indeed very confusing.

Would an easy solution be to implement 'persist' as an input argument for the '_environment() method? It oviously makes no sense to persist the auth from an existing file, but in my case I actually expected earthaccess.login(strategy='environment', persist=True) to write a file.

At the very least there should be a warning/error raised if the user enables persist and chooses a strategy that does not implement this functionality?

jbusecke avatar Jul 02 '25 15:07 jbusecke

Hi @jbusecke yeah I think what you said makes sense. Ideally, users won't have to use persist at all, because that means that we are leaving our credentials on a file(potentially in a cloud environment). There is a new functionality where earthaccess will only use a NASA EDL token (bearer token) so no there is no need to use username/password it just got merged in #1020 so I expect will be available soon. Maybe with a warning for this case(if there is a PR for it 😸).

betolink avatar Jul 02 '25 18:07 betolink