Skip to content

Commit

Permalink
Improve Colab authentication (#1879)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Jan 12, 2024
1 parent c67e951 commit 860e991
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions geemap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def ee_initialize(

Args:
token_name (str, optional): The name of the Earth Engine token. Defaults to "EARTHENGINE_TOKEN".
In Colab, you can also set a secret named "EE_PROJECT_ID" to initialize Earth Engine.
auth_mode (str, optional): The authentication mode, can be one of colab, notebook, localhost, or gcloud.
See https://developers.google.com/earth-engine/guides/auth for more details. Defaults to None.
service_account (bool, optional): If True, use a service account. Defaults to False.
Expand All @@ -61,9 +62,16 @@ def ee_initialize(

if auth_mode is None:
if in_colab_shell():
auth_mode = "notebook"
from google.colab import userdata

try:
project_id = userdata.get("EE_PROJECT_ID")
auth_mode = "colab"
kwargs["project"] = project_id
except Exception:
auth_mode = "notebook"
else:
auth_mode = "localhost"
auth_mode = "notebook"

auth_args["auth_mode"] = auth_mode

Expand Down Expand Up @@ -122,16 +130,6 @@ 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()

ee.Initialize(**kwargs)

Expand Down

0 comments on commit 860e991

Please sign in to comment.