-
Notifications
You must be signed in to change notification settings - Fork 311
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
fetch_id_token_credentials doesn't follow AIP-4110 #1331
Comments
We currently use a workaround:
The following code works, but it's not complete (doesn't support all kinds of credentials) and also does some redundant requests to metadata server. def fixed_fetch_id_token_credentials(audience: str, request=None):
"""Get OpenID credentials from the current environment.
NOTE: This is needed only because google.oauth2.id_token.fetch_id_token_credentials doesn't support impersonated
credentials. Once it does, this function can be removed.
"""
creds, _project_id = google.auth.default()
if request is None:
request = google.auth.transport.requests.Request()
if isinstance(creds, google.auth.impersonated_credentials.Credentials):
id_creds = google.auth.impersonated_credentials.IDTokenCredentials(
creds, audience, include_email=True
)
elif isinstance(creds, google.oauth2.service_account.Credentials):
id_creds = google.oauth2.service_account.IDTokenCredentials(
signer=creds.signer,
service_account_email=creds.service_account_email,
token_uri=creds._token_uri,
quota_project_id=creds.quota_project_id,
target_audience=audience,
)
elif isinstance(creds, google.auth.compute_engine.credentials.Credentials):
id_creds = google.auth.compute_engine.credentials.IDTokenCredentials(
request,
audience,
use_metadata_identity_endpoint=True,
quota_project_id=creds.quota_project_id,
)
elif isinstance(creds, google.oauth2.credentials.Credentials):
raise ValueError(
"IDTokens are not supported for human accounts. Provide a service account instead."
)
else:
raise ValueError(f"Unknown credentials type {type(creds)}")
return id_creds We'd appreciate the library supporting this natively so that we could delete the code. |
Indeed! I just came across this difference as well, as in the Go library it's been implemented adherent to the AIP spec. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AIP-4110 specifies where should client libraries load credentials from. It's correctly used by
google.auth.default()
, which loads the OAuth credentials (ie credentials with access token).In our service, we need the same default credentials, but our use case requires OpenID credentials.
google.oauth2.id_token.fetch_id_token_credentials()
pretty much does this, as it also states in the doc string:However, there are notable differences in the OpenID flow:
It would be good if
fetch_id_token_credentials()
would matchgoogle.auth.default()
.The text was updated successfully, but these errors were encountered: