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

[Identity] Correctly implement TokenCredential protocols #31047

Merged
merged 21 commits into from
Aug 4, 2023

Conversation

mccoyp
Copy link
Member

@mccoyp mccoyp commented Jul 10, 2023

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.

@mccoyp mccoyp added Client This issue points to a problem in the data-plane of the library. Azure.Identity labels Jul 10, 2023
@mccoyp mccoyp requested review from lmazuel, pvaneck and xiangyan99 July 10, 2023 18:27
@azure-sdk
Copy link
Collaborator

API change check

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

azure-identity

@mccoyp mccoyp force-pushed the cred-protocol-sig branch from 5999970 to 437b2d1 Compare July 27, 2023 18:46
@mccoyp mccoyp force-pushed the cred-protocol-sig branch from 345bfca to 475f782 Compare July 28, 2023 00:40
@mccoyp mccoyp force-pushed the cred-protocol-sig branch from f95549c to 65d7552 Compare July 28, 2023 20:44
@mccoyp mccoyp marked this pull request as ready for review July 28, 2023 20:45
@mccoyp mccoyp requested a review from xiangyan99 July 28, 2023 20:45
@xiangyan99
Copy link
Member

xiangyan99 commented Jul 31, 2023

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

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

@mccoyp
Copy link
Member Author

mccoyp commented Aug 1, 2023

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

Copy link
Member

@pvaneck pvaneck left a comment

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.

@mccoyp mccoyp requested review from pvaneck and xiangyan99 August 2, 2023 19:34
@mccoyp
Copy link
Member Author

mccoyp commented Aug 4, 2023

@xiangyan99 @pvaneck Do you think this can make it into next week's release?

Copy link
Member

@pvaneck pvaneck left a comment

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.

@mccoyp
Copy link
Member Author

mccoyp commented Aug 4, 2023

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 🙂

@mccoyp mccoyp enabled auto-merge (squash) August 4, 2023 20:50
@mccoyp mccoyp disabled auto-merge August 4, 2023 20:52
@mccoyp mccoyp merged commit 0464b2a into Azure:main Aug 4, 2023
@mccoyp mccoyp deleted the cred-protocol-sig branch August 4, 2023 21:16
@pvaneck pvaneck mentioned this pull request Dec 1, 2023
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