-
Notifications
You must be signed in to change notification settings - Fork 3.2k
User authentication API for applications #10612
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6da3cc6
AuthenticationRecord
chlowell 6ff4e3e
AuthenticationRequiredError
chlowell 348cfd3
base class for credentials requiring user interaction
chlowell a9499da
browser, device code credentials are InteractiveCredentials
chlowell 55c639b
UsernamePasswordCredential opts out of shared cache
chlowell bbe033b
tests
chlowell a2e467a
update changelog
chlowell 5ded022
add default scopes for known clouds
chlowell f1b4270
persistent cache disabled by default
chlowell 8281b29
remove additional_data from AuthenticationRecord
chlowell c1c0235
reword changelog
chlowell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
sdk/identity/azure-identity/azure/identity/_auth_record.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
| import json | ||
|
|
||
|
|
||
| class AuthenticationRecord(object): | ||
| """A record which can initialize :class:`DeviceCodeCredential` or :class:`InteractiveBrowserCredential`""" | ||
|
|
||
| def __init__(self, tenant_id, client_id, authority, home_account_id, username): | ||
| # type: (str, str, str, str, str) -> None | ||
| self._authority = authority | ||
| self._client_id = client_id | ||
| self._home_account_id = home_account_id | ||
| self._tenant_id = tenant_id | ||
| self._username = username | ||
|
|
||
| @property | ||
| def authority(self): | ||
| # type: () -> str | ||
| return self._authority | ||
|
|
||
| @property | ||
| def client_id(self): | ||
| # type: () -> str | ||
| return self._client_id | ||
|
|
||
| @property | ||
| def home_account_id(self): | ||
| # type: () -> str | ||
| return self._home_account_id | ||
|
|
||
| @property | ||
| def tenant_id(self): | ||
| # type: () -> str | ||
| return self._tenant_id | ||
|
|
||
| @property | ||
| def username(self): | ||
| # type: () -> str | ||
| """The authenticated user's username""" | ||
| return self._username | ||
|
|
||
| @classmethod | ||
| def deserialize(cls, json_string): | ||
| # type: (str) -> AuthenticationRecord | ||
| """Deserialize a record from JSON""" | ||
|
|
||
| deserialized = json.loads(json_string) | ||
|
|
||
| return cls( | ||
| authority=deserialized["authority"], | ||
| client_id=deserialized["client_id"], | ||
| home_account_id=deserialized["home_account_id"], | ||
| tenant_id=deserialized["tenant_id"], | ||
| username=deserialized["username"], | ||
| ) | ||
|
|
||
| def serialize(self): | ||
| # type: () -> str | ||
| """Serialize the record to JSON""" | ||
|
|
||
| record = { | ||
| "authority": self._authority, | ||
| "client_id": self._client_id, | ||
| "home_account_id": self._home_account_id, | ||
| "tenant_id": self._tenant_id, | ||
| "username": self._username, | ||
| } | ||
|
|
||
| return json.dumps(record) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why AuthenticationRequiredError is a subclass of CredentialUnavailableError?
It seems to me AuthenticationRequiredError is a HttpRequestError but CredentialUnavailableError may be not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silent authentication can succeed or fail without sending a request. The question is really about the behavior of chained credentials: if a credential is configured to authenticate silently only, should a chain try its next credential when silent auth fails? I lean toward "yes", hence CredentialUnavailableError. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't go under HttpRequestError, because as Charles said there might have been no request made when we determine that authentication is required. As far as if it should fall under CredentialUnavailableError, i.e. allow other credentials in a chain to be attempted, I also lean towards yes. However, as we develop this more we might find we have to tweak this over the course of the preview.