-
Notifications
You must be signed in to change notification settings - Fork 211
Added withFmi method for cca app #876
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
Open
4gust
wants to merge
2
commits into
dev
Choose a base branch
from
4gust/with-fmi
base: dev
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.
+675
−10
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| from .mex import send_request as mex_send_request | ||
| from .wstrust_request import send_request as wst_send_request | ||
| from .wstrust_response import * | ||
| from .token_cache import TokenCache, _get_username, _GRANT_TYPE_BROKER | ||
| from .token_cache import TokenCache, _get_username, _GRANT_TYPE_BROKER, _compute_ext_cache_key | ||
| import msal.telemetry | ||
| from .region import _detect_region | ||
| from .throttled_http_client import ThrottledHttpClient | ||
|
|
@@ -1571,6 +1571,9 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it( | |
| key_id = kwargs.get("data", {}).get("key_id") | ||
| if key_id: # Some token types (SSH-certs, POP) are bound to a key | ||
| query["key_id"] = key_id | ||
| ext_cache_key = _compute_ext_cache_key(kwargs.get("data", {})) | ||
| if ext_cache_key: # FMI tokens need cache isolation by path | ||
| query["ext_cache_key"] = ext_cache_key | ||
| now = time.time() | ||
| refresh_reason = msal.telemetry.AT_ABSENT | ||
| for entry in self.token_cache.search( # A generator allows us to | ||
|
|
@@ -2491,6 +2494,32 @@ def remove_tokens_for_client(self): | |
| self.token_cache.remove_at(at) | ||
| # acquire_token_for_client() obtains no RTs, so we have no RT to remove | ||
|
|
||
| def acquire_token_for_client_with_fmi_path(self, scopes, fmi_path, claims_challenge=None, **kwargs): | ||
| """Acquires token for the current confidential client with a Federated Managed Identity (FMI) path. | ||
|
|
||
| This is a convenience wrapper around :func:`~acquire_token_for_client` | ||
| that attaches the ``fmi_path`` parameter to the token request body. | ||
|
|
||
| :param list[str] scopes: (Required) | ||
| Scopes requested to access a protected API (a resource). | ||
| :param str fmi_path: (Required) | ||
| The Federated Managed Identity path to attach to the request. | ||
| :param claims_challenge: | ||
| The claims_challenge parameter requests specific claims requested by the resource provider | ||
| in the form of a claims_challenge directive in the www-authenticate header to be | ||
| returned from the UserInfo Endpoint and/or in the ID Token and/or Access Token. | ||
| It is a string of a JSON object which contains lists of claims being requested from these locations. | ||
|
|
||
| :return: A dict representing the json response from Microsoft Entra: | ||
|
|
||
| - A successful response would contain "access_token" key, | ||
| - an error response would contain "error" and usually "error_description". | ||
| """ | ||
| data = kwargs.pop("data", {}) | ||
| data["fmi_path"] = fmi_path | ||
|
Member
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. Are the tokens cached like in MSAL .NET and MSAL GO? I don't think they are. I see a PR here that look at proper caching #759 but I am not sure it is compliant with the rest. |
||
| return self.acquire_token_for_client( | ||
| scopes, claims_challenge=claims_challenge, data=data, **kwargs) | ||
|
|
||
| def acquire_token_on_behalf_of(self, user_assertion, scopes, claims_challenge=None, **kwargs): | ||
| """Acquires token using on-behalf-of (OBO) flow. | ||
|
|
||
|
|
||
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.
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.
Should we have FMI path as one of the kwargs instead? Creating an entire new API seems pretty heavy.