Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Colab authentication #1879

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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