-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Honor scopes specified by Track 2 SDK #15184
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
Changes from all commits
44e1ae3
0f76f51
d9da324
ea84b44
6125237
5b42f19
c86dedb
f63ba04
aa2696d
c08ef44
76e0845
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1165,3 +1165,36 @@ def handle_version_update(): | |||
| refresh_known_clouds() | ||||
| except Exception as ex: # pylint: disable=broad-except | ||||
| logger.warning(ex) | ||||
|
|
||||
|
|
||||
| def resource_to_scopes(resource): | ||||
| """Convert the ADAL resource ID to MSAL scopes by appending the /.default suffix and return a list. | ||||
| For example: 'https://management.core.windows.net/' -> ['https://management.core.windows.net/.default'] | ||||
| :param resource: The ADAL resource ID | ||||
| :return: A list of scopes | ||||
| """ | ||||
| if 'datalake' in resource or 'batch' in resource or 'database' in resource: | ||||
|
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. Is it possible that we move this tricky logic from core to module level?
Member
Author
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. Good point. Currently |
||||
| # For datalake, batch and database, the slash must be doubled due to service issue, like | ||||
| # https://datalake.azure.net//.default | ||||
| # TODO: This should be fixed on the service side. | ||||
| scope = resource + '/.default' | ||||
| else: | ||||
| scope = resource.rstrip('/') + '/.default' | ||||
| return [scope] | ||||
|
|
||||
|
|
||||
| def scopes_to_resource(scopes): | ||||
| """Convert MSAL scopes to ADAL resource by stripping the /.default suffix and return a str. | ||||
| For example: ['https://management.core.windows.net/.default'] -> 'https://management.core.windows.net/' | ||||
|
|
||||
| :param scopes: The MSAL scopes. It can be a list or tuple of string | ||||
| :return: The ADAL resource | ||||
| :rtype: str | ||||
| """ | ||||
| scope = scopes[0] | ||||
|
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. Do we only support one scope now as it is a list?
Member
Author
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.
|
||||
| if scope.endswith(".default"): | ||||
arrownj marked this conversation as resolved.
Show resolved
Hide resolved
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.
Do we need make this case insensitive?
Member
Author
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. No. |
||||
| scope = scope[:-len(".default")] | ||||
|
|
||||
| # Trim extra ending slashes. https://datalake.azure.net// -> https://datalake.azure.net/ | ||||
| scope = scope.rstrip('/') + '/' | ||||
| return scope | ||||
|
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. Is it expected that "scope" is https://management.core.windows.net/ or it should be https://management.core.windows.net?
Member
Author
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. Yes. See
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,8 +129,7 @@ def validate_client_parameters(cmd, namespace): | |
| if is_storagev2(prefix): | ||
| from azure.cli.core._profile import Profile | ||
| profile = Profile(cli_ctx=cmd.cli_ctx) | ||
| n.token_credential, _, _ = profile.get_login_credentials( | ||
| resource="https://storage.azure.com", subscription_id=n._subscription) | ||
| n.token_credential, _, _ = profile.get_login_credentials(subscription_id=n._subscription) | ||
|
Member
Author
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.
STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default" |
||
| # Otherwise, we will assume it is in track1 and keep previous token updater | ||
| else: | ||
| n.token_credential = _create_token_credential(cmd.cli_ctx) | ||
|
|
||
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.
Add a patch to handle issue Azure/azure-sdk-for-python#12947 in old Track 2 SDKs.