-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Core auth flows #40084
Open
xiangyan99
wants to merge
8
commits into
main
Choose a base branch
from
core_auth_flows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−13
Open
Core auth flows #40084
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e753010
Added `auth_flows` support in `BearerTokenCredentialPolicy`
xiangyan99 25f9a53
update
xiangyan99 e01599a
updates
xiangyan99 4dc1500
updates
xiangyan99 f9f8761
disable mypy "typeddict-unknown-key"
xiangyan99 7ad3fc4
update
xiangyan99 751efbc
Merge branch 'main' into core_auth_flows
xiangyan99 706e74c
update
xiangyan99 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 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 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 |
---|---|---|
|
@@ -32,15 +32,22 @@ class _BearerTokenCredentialPolicyBase: | |
:param credential: The credential. | ||
:type credential: ~corehttp.credentials.TokenCredential | ||
:param str scopes: Lets you specify the type of access needed. | ||
:keyword list[dict[str, str]] auth_flows: A list of authentication flows to use for the credential. | ||
""" | ||
|
||
# pylint: disable=unused-argument | ||
def __init__( | ||
self, credential: "TokenCredential", *scopes: str, **kwargs: Any # pylint: disable=unused-argument | ||
self, | ||
credential: "TokenCredential", | ||
*scopes: str, | ||
auth_flows: Optional[list[dict[str, str]]] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
super(_BearerTokenCredentialPolicyBase, self).__init__() | ||
self._scopes = scopes | ||
self._credential = credential | ||
self._token: Optional["AccessTokenInfo"] = None | ||
self._auth_flows = auth_flows | ||
|
||
@staticmethod | ||
def _enforce_https(request: PipelineRequest[HTTPRequestType]) -> None: | ||
|
@@ -83,20 +90,25 @@ class BearerTokenCredentialPolicy(_BearerTokenCredentialPolicyBase, HTTPPolicy[H | |
:param credential: The credential. | ||
:type credential: ~corehttp.TokenCredential | ||
:param str scopes: Lets you specify the type of access needed. | ||
:keyword list[dict[str, str]] auth_flows: A list of authentication flows to use for the credential. | ||
:raises: :class:`~corehttp.exceptions.ServiceRequestError` | ||
""" | ||
|
||
def on_request(self, request: PipelineRequest[HTTPRequestType]) -> None: | ||
def on_request( | ||
self, request: PipelineRequest[HTTPRequestType], *, auth_flows: Optional[list[dict[str, str]]] = None | ||
) -> None: | ||
"""Called before the policy sends a request. | ||
|
||
The base implementation authorizes the request with a bearer token. | ||
|
||
:param ~corehttp.runtime.pipeline.PipelineRequest request: the request | ||
:keyword list[dict[str, str]] auth_flows: A list of authentication flows to use for the credential. | ||
""" | ||
self._enforce_https(request) | ||
|
||
if self._token is None or self._need_new_token: | ||
self._token = self._credential.get_token_info(*self._scopes) | ||
options: TokenRequestOptions = {"auth_flows": auth_flows} if auth_flows else {} # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is optional. I would hold until the GA at least. :) |
||
self._token = self._credential.get_token_info(*self._scopes, options=options) | ||
self._update_headers(request.http_request.headers, self._token.token) | ||
|
||
def authorize_request(self, request: PipelineRequest[HTTPRequestType], *scopes: str, **kwargs: Any) -> None: | ||
|
@@ -124,7 +136,7 @@ def send(self, request: PipelineRequest[HTTPRequestType]) -> PipelineResponse[HT | |
:return: The pipeline response object | ||
:rtype: ~corehttp.runtime.pipeline.PipelineResponse | ||
""" | ||
self.on_request(request) | ||
self.on_request(request, auth_flows=self._auth_flows) | ||
try: | ||
response = self.next.send(request) | ||
except Exception: | ||
|
This file contains 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 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 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
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.
Do we need to take in
auth_flows
as a parameter here? Or can we just access it in this method viaself._auth_flows
?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.
I have the parameter because we will support per-operation auth_flow. :)