Skip to content

Commit

Permalink
Improve ee authentication on Colab (#1806)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Nov 2, 2023
1 parent bc0f09b commit 6fc21c6
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions geemap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def ee_initialize(

if ee.data._credentials is None:
ee_token = os.environ.get(token_name)
if in_colab_shell():
from google.colab import userdata
try:
ee_token = userdata.get(token_name)
except Exception:
pass
if service_account:
try:
credential_file_path = os.path.expanduser(
Expand Down Expand Up @@ -107,16 +113,16 @@ def ee_initialize(
) # deals with token generated by old auth method.
with open(credential_file_path, "w") as f:
f.write(credential)
elif in_colab_shell():
if credentials_in_drive() and (not credentials_in_colab()):
copy_credentials_to_colab()
elif not credentials_in_colab:
ee.Authenticate(**auth_args)
if is_drive_mounted() and (not credentials_in_drive()):
copy_credentials_to_drive()
else:
if is_drive_mounted():
copy_credentials_to_drive()
# elif in_colab_shell():
# if credentials_in_drive() and (not credentials_in_colab()):
# copy_credentials_to_colab()
# elif not credentials_in_colab:
# ee.Authenticate(**auth_args)
# if is_drive_mounted() and (not credentials_in_drive()):
# copy_credentials_to_drive()
# else:
# if is_drive_mounted():
# copy_credentials_to_drive()

ee.Initialize(**kwargs)

Expand Down

0 comments on commit 6fc21c6

Please sign in to comment.