Skip to content

[Identity] Correctly implement TokenCredential protocols - #31047

Merged
Laia Patiño (laiapat) merged 21 commits into
Azure:mainfrom
laiapat:cred-protocol-sig
Aug 4, 2023
Merged

[Identity] Correctly implement TokenCredential protocols#31047
Laia Patiño (laiapat) merged 21 commits into
Azure:mainfrom
laiapat:cred-protocol-sig

Conversation

@laiapat

@laiapat Laia Patiño (laiapat) commented Jul 10, 2023

Copy link
Copy Markdown
Member

Description

Resolves #25175.

azure-identity credentials should all implement the TokenCredential protocol, but they technically don't at the moment. For both sync and async credentials, our get_token methods don't include all the parameters specified in the protocol. This PR update method signatures to match, and clarifies which parameters may be ignored in docstrings.

Validating live Key Vault pipeline run: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=2958066&view=results

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Comment thread sdk/identity/azure-identity/azure/identity/_credentials/default.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/_credentials/environment.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/_credentials/managed_identity.py Outdated
@azure-sdk

Copy link
Copy Markdown
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-identity

Comment thread sdk/identity/azure-identity/azure/identity/_credentials/chained.py Outdated
@xiangyan99

Xiang Yan (xiangyan99) commented Jul 31, 2023

Copy link
Copy Markdown
Member

Is it possible that claims/tenant_id are passed into transport?

(want to check if we need to add such protection in core)

@laiapat

Laia Patiño (laiapat) commented Aug 1, 2023

Copy link
Copy Markdown
Member Author

Is it possible that claims/tenant_id are passed into transport?

(want to check if we need to add such protection in core)

This hasn't happened in live tests, but that doesn't give us full coverage of all credentials. I'm writing tests now to make sure the transport layer doesn't receive these.

EDIT: added in fc5410b

Comment thread sdk/identity/azure-identity/azure/identity/_credentials/azd_cli.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/_credentials/chained.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/_credentials/default.py Outdated

@pvaneck Paul Van Eck (pvaneck) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, @mccoyp! Just some minor doc fixes I think should go in.

With the recent support for CAE, all get_token methods for user credentials and service principal credentials should support claims (this is mainly any credential that uses AadClient or inherits MsalCredential, example of claims usage). So, I think it makes sense to update the docstrings for these credentials.

Comment thread sdk/identity/azure-identity/azure/identity/_credentials/authorization_code.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/_credentials/environment.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/_internal/get_token_mixin.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/aio/_credentials/authorization_code.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/aio/_credentials/environment.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/aio/_credentials/shared_cache.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/aio/_internal/get_token_mixin.py Outdated
@laiapat

Copy link
Copy Markdown
Member Author

Xiang Yan (@xiangyan99) Paul Van Eck (@pvaneck) Do you think this can make it into next week's release?

@pvaneck Paul Van Eck (pvaneck) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to have nice this in if possible provided we can get the additional API changes approved. One thing I noticed when looking at the apiview was the removal of the Any type from all the kwargs in get_token. What was the motivation for this? I see that the protocol method has the Any still.

@laiapat

Copy link
Copy Markdown
Member Author

I think it would be nice to have nice this in if possible provided we can get the additional API changes approved. One thing I noticed when looking at the apiview was the removal of the Any type from all the kwargs in get_token. What was the motivation for this? I see that the protocol method has the Any still.

I had removed them because of an impression that **kwargs should be left untyped, but a double-check with our static typing guide showed we should use Any. And that's true about the protocol's typing as well, so I just updated credential signatures to match 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Identity Client This issue points to a problem in the data-plane of the library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client creation with DefaultAzureCredential raises PyCharm typing warning

4 participants