-
Notifications
You must be signed in to change notification settings - Fork 3.3k
graph: support admin consent #8804
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
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 |
|---|---|---|
|
|
@@ -807,6 +807,34 @@ def delete_permission(cmd, identifier, api): | |
| return graph_client.applications.patch(application.object_id, update_parameter) | ||
|
|
||
|
|
||
| def admin_consent(cmd, identifier): | ||
| import requests | ||
| from azure.cli.core.cloud import AZURE_PUBLIC_CLOUD | ||
| from azure.cli.core._profile import Profile | ||
|
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. Importing from private namespaces always raises my eyebrows. Is
Contributor
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.
|
||
| from azure.cli.core.commands.client_factory import UA_AGENT | ||
| from azure.cli.core.util import should_disable_connection_verify | ||
| if cmd.cli_ctx.cloud.name != AZURE_PUBLIC_CLOUD.name: | ||
| raise CLIError('This command is not yet supported on sovereign clouds') | ||
| # we will leverage portal endpoints to get admin consent done | ||
| graph_client = _graph_client_factory(cmd.cli_ctx) | ||
| application = show_application(graph_client.applications, identifier) | ||
| url = 'https://main.iam.ad.ext.azure.com/api/RegisteredApplications/{}/Consent?onBehalfOfAll=true'.format( | ||
| application.app_id) | ||
| profile = Profile() | ||
|
|
||
| # the key is to get the access token to the portal resource: | ||
| access_token = profile.get_raw_token('74658136-14ec-4630-ad9b-26e160ff0fc6') | ||
| headers = { | ||
| 'Authorization': "Bearer " + access_token[0][1], | ||
| 'Accept-Encoding': 'gzip, deflate, br', | ||
| 'x-ms-client-request-id': str(uuid.uuid4()), | ||
| 'User-Agent': UA_AGENT | ||
| } | ||
| response = requests.post(url, headers=headers, verify=not should_disable_connection_verify()) | ||
| if not response.ok: | ||
| raise CLIError(response.reason) | ||
|
|
||
|
|
||
| def grant_application(cmd, identifier, api, consent_type=None, principal_id=None, | ||
| expires='1', scope='user_impersonation'): | ||
| graph_client = _graph_client_factory(cmd.cli_ctx) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.