{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/azure-cli/pulls/comments/208549259","pull_request_review_id":144378721,"id":208549259,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwODU0OTI1OQ==","diff_hunk":"@@ -667,6 +668,62 @@ def create_application(client, display_name, homepage=None, identifier_uris=None\n     return result\n \n \n+def grant_application(cmd, identifier, appid, expires='1'):\n+    if not appid:\n+        raise CLIError(\"'--appid' is required for grant OAuth2 permissions\")\n+\n+    graph_client = _graph_client_factory(cmd.cli_ctx)\n+\n+    # Get the Service principal ObjectId for the client app\n+\n+    sps = list(graph_client.service_principals.list(\n+        filter=\"appId eq '{}'\".format(identifier)))","path":"src/command_modules/azure-cli-role/azure/cli/command_modules/role/custom.py","position":43,"original_position":43,"commit_id":"1a34dd9f8329bd7e25d5f7b64b82665c26af8394","original_commit_id":"1a34dd9f8329bd7e25d5f7b64b82665c26af8394","user":{"login":"shanepeckham","id":9840775,"node_id":"MDQ6VXNlcjk4NDA3NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/9840775?v=4","gravatar_id":"","url":"https://api.github.com/users/shanepeckham","html_url":"https://github.com/shanepeckham","followers_url":"https://api.github.com/users/shanepeckham/followers","following_url":"https://api.github.com/users/shanepeckham/following{/other_user}","gists_url":"https://api.github.com/users/shanepeckham/gists{/gist_id}","starred_url":"https://api.github.com/users/shanepeckham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shanepeckham/subscriptions","organizations_url":"https://api.github.com/users/shanepeckham/orgs","repos_url":"https://api.github.com/users/shanepeckham/repos","events_url":"https://api.github.com/users/shanepeckham/events{/privacy}","received_events_url":"https://api.github.com/users/shanepeckham/received_events","type":"User","site_admin":false},"body":"Extended ```list_sps``` to include search by appid/clientid\r\n\r\n```\r\ndef list_sps(client, spn=None, display_name=None, query_filter=None, appid=None):\r\n    sub_filters = []\r\n    if query_filter:\r\n        sub_filters.append(query_filter)\r\n    if spn:\r\n        sub_filters.append(\"servicePrincipalNames/any(c:c eq '{}')\".format(spn))\r\n    if display_name:\r\n        sub_filters.append(\"startswith(displayName,'{}')\".format(display_name))\r\n    if appid:\r\n        sub_filters.append(\"appId eq '{}'\".format(appid))\r\n\r\n    return client.list(filter=(' and '.join(sub_filters)))\r\n```","created_at":"2018-08-08T11:43:14Z","updated_at":"2018-08-08T11:43:14Z","html_url":"https://github.com/Azure/azure-cli/pull/6975#discussion_r208549259","pull_request_url":"https://api.github.com/repos/Azure/azure-cli/pulls/6975","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-cli/pulls/comments/208549259"},"html":{"href":"https://github.com/Azure/azure-cli/pull/6975#discussion_r208549259"},"pull_request":{"href":"https://api.github.com/repos/Azure/azure-cli/pulls/6975"}},"in_reply_to_id":208345582},"pull_request":{"url":"https://api.github.com/repos/Azure/azure-cli/pulls/6975","id":206702753,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA2NzAyNzUz","html_url":"https://github.com/Azure/azure-cli/pull/6975","diff_url":"https://github.com/Azure/azure-cli/pull/6975.diff","patch_url":"https://github.com/Azure/azure-cli/pull/6975.patch","issue_url":"https://api.github.com/repos/Azure/azure-cli/issues/6975","number":6975,"state":"open","locked":false,"title":"Add new az ad app grant command to grant OAuth2 permissions to AAD registered apps","user":{"login":"shanepeckham","id":9840775,"node_id":"MDQ6VXNlcjk4NDA3NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/9840775?v=4","gravatar_id":"","url":"https://api.github.com/users/shanepeckham","html_url":"https://github.com/shanepeckham","followers_url":"https://api.github.com/users/shanepeckham/followers","following_url":"https://api.github.com/users/shanepeckham/following{/other_user}","gists_url":"https://api.github.com/users/shanepeckham/gists{/gist_id}","starred_url":"https://api.github.com/users/shanepeckham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shanepeckham/subscriptions","organizations_url":"https://api.github.com/users/shanepeckham/orgs","repos_url":"https://api.github.com/users/shanepeckham/repos","events_url":"https://api.github.com/users/shanepeckham/events{/privacy}","received_events_url":"https://api.github.com/users/shanepeckham/received_events","type":"User","site_admin":false},"body":"This is needed so that we can programmatically grant OAuth2 consent to an application in Azure Active Directory. This is the supported and correct way to do this respecting customer approval workflows. Example use case includes Azure Kubernetes Service RBAC integration with Azure Active Directory.\r\n\r\nThis PR has the following dependencies upstream that need to be merged first:\r\n* https://github.com/Azure/azure-rest-api-specs/pull/3563 - this is the extension to the REST spec which has auto-generated PRs for all of the Azure SDKs\r\n* https://github.com/Azure/azure-sdk-for-python/pull/3063 - this is the autorest generation of the the azure-sdk-for-python\r\n\r\nNew command has the following help format:\r\n\r\n```\r\nad app grant = \"\"\"\r\n    type: command\r\n    short-summary: Grant the app OAuth2 permissions for the respective apps\r\n    examples:\r\n        - name: update a native application with OAuth2 permissions with space separated clientIds for AAD apps with TTL of 1 year\r\n          text: az ad app update --id e042ec79-34cd-498f-9d9f-1234234 --appid a0322f79-57df-498f-9d9f-12678 --expires 1\r\n```\r\n\r\nUsage:\r\n\r\n```\r\naz ad app grant --id 14cb4751-8285-4c77-a694-4583a07cc1a7 --appid ce848207-8603-4eb3-9b8e-59023d31f742 --expires never      \r\n```\r\n\r\naz cmd help:\r\n```\r\naz ad app grant --help                                                                                                                                                                                                                                                                                                                                                    []\r\nCommand\r\n    az ad app grant : Grant the app OAuth2 permissions for the respective apps.\r\n\r\nArguments\r\n    --appid [Required] : ClientId of the app you want to grant permissions for.\r\n    --id    [Required] : ClientId of the app you want to grant permissions to.\r\n    --expires          : Expiry date for the permissions in years, options include 1, 2 or never.\r\n                         Default: 1.\r\n```\r\n\r\n\r\n\r\n---\r\n\r\nThis checklist is used to make sure that common guidelines for a pull request are followed.\r\n\r\n- [ X] I adhere to the [Command Guidelines](https://github.com/Azure/azure-cli/blob/dev/doc/command_guidelines.md).\r\n","created_at":"2018-08-07T13:43:27Z","updated_at":"2018-08-08T11:43:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":{"login":"yugangw-msft","id":6014209,"node_id":"MDQ6VXNlcjYwMTQyMDk=","avatar_url":"https://avatars1.githubusercontent.com/u/6014209?v=4","gravatar_id":"","url":"https://api.github.com/users/yugangw-msft","html_url":"https://github.com/yugangw-msft","followers_url":"https://api.github.com/users/yugangw-msft/followers","following_url":"https://api.github.com/users/yugangw-msft/following{/other_user}","gists_url":"https://api.github.com/users/yugangw-msft/gists{/gist_id}","starred_url":"https://api.github.com/users/yugangw-msft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yugangw-msft/subscriptions","organizations_url":"https://api.github.com/users/yugangw-msft/orgs","repos_url":"https://api.github.com/users/yugangw-msft/repos","events_url":"https://api.github.com/users/yugangw-msft/events{/privacy}","received_events_url":"https://api.github.com/users/yugangw-msft/received_events","type":"User","site_admin":false},"assignees":[{"login":"yugangw-msft","id":6014209,"node_id":"MDQ6VXNlcjYwMTQyMDk=","avatar_url":"https://avatars1.githubusercontent.com/u/6014209?v=4","gravatar_id":"","url":"https://api.github.com/users/yugangw-msft","html_url":"https://github.com/yugangw-msft","followers_url":"https://api.github.com/users/yugangw-msft/followers","following_url":"https://api.github.com/users/yugangw-msft/following{/other_user}","gists_url":"https://api.github.com/users/yugangw-msft/gists{/gist_id}","starred_url":"https://api.github.com/users/yugangw-msft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yugangw-msft/subscriptions","organizations_url":"https://api.github.com/users/yugangw-msft/orgs","repos_url":"https://api.github.com/users/yugangw-msft/repos","events_url":"https://api.github.com/users/yugangw-msft/events{/privacy}","received_events_url":"https://api.github.com/users/yugangw-msft/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Azure/azure-cli/pulls/6975/commits","review_comments_url":"https://api.github.com/repos/Azure/azure-cli/pulls/6975/comments","review_comment_url":"https://api.github.com/repos/Azure/azure-cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/azure-cli/issues/6975/comments","statuses_url":"https://api.github.com/repos/Azure/azure-cli/statuses/1a34dd9f8329bd7e25d5f7b64b82665c26af8394","head":{"label":"shanepeckham:az_ad_app_grant_command","ref":"az_ad_app_grant_command","sha":"1a34dd9f8329bd7e25d5f7b64b82665c26af8394","user":{"login":"shanepeckham","id":9840775,"node_id":"MDQ6VXNlcjk4NDA3NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/9840775?v=4","gravatar_id":"","url":"https://api.github.com/users/shanepeckham","html_url":"https://github.com/shanepeckham","followers_url":"https://api.github.com/users/shanepeckham/followers","following_url":"https://api.github.com/users/shanepeckham/following{/other_user}","gists_url":"https://api.github.com/users/shanepeckham/gists{/gist_id}","starred_url":"https://api.github.com/users/shanepeckham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shanepeckham/subscriptions","organizations_url":"https://api.github.com/users/shanepeckham/orgs","repos_url":"https://api.github.com/users/shanepeckham/repos","events_url":"https://api.github.com/users/shanepeckham/events{/privacy}","received_events_url":"https://api.github.com/users/shanepeckham/received_events","type":"User","site_admin":false},"repo":{"id":142869110,"node_id":"MDEwOlJlcG9zaXRvcnkxNDI4NjkxMTA=","name":"azure-cli","full_name":"shanepeckham/azure-cli","owner":{"login":"shanepeckham","id":9840775,"node_id":"MDQ6VXNlcjk4NDA3NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/9840775?v=4","gravatar_id":"","url":"https://api.github.com/users/shanepeckham","html_url":"https://github.com/shanepeckham","followers_url":"https://api.github.com/users/shanepeckham/followers","following_url":"https://api.github.com/users/shanepeckham/following{/other_user}","gists_url":"https://api.github.com/users/shanepeckham/gists{/gist_id}","starred_url":"https://api.github.com/users/shanepeckham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shanepeckham/subscriptions","organizations_url":"https://api.github.com/users/shanepeckham/orgs","repos_url":"https://api.github.com/users/shanepeckham/repos","events_url":"https://api.github.com/users/shanepeckham/events{/privacy}","received_events_url":"https://api.github.com/users/shanepeckham/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shanepeckham/azure-cli","description":"Command-line tools for Azure.","fork":true,"url":"https://api.github.com/repos/shanepeckham/azure-cli","forks_url":"https://api.github.com/repos/shanepeckham/azure-cli/forks","keys_url":"https://api.github.com/repos/shanepeckham/azure-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shanepeckham/azure-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shanepeckham/azure-cli/teams","hooks_url":"https://api.github.com/repos/shanepeckham/azure-cli/hooks","issue_events_url":"https://api.github.com/repos/shanepeckham/azure-cli/issues/events{/number}","events_url":"https://api.github.com/repos/shanepeckham/azure-cli/events","assignees_url":"https://api.github.com/repos/shanepeckham/azure-cli/assignees{/user}","branches_url":"https://api.github.com/repos/shanepeckham/azure-cli/branches{/branch}","tags_url":"https://api.github.com/repos/shanepeckham/azure-cli/tags","blobs_url":"https://api.github.com/repos/shanepeckham/azure-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shanepeckham/azure-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shanepeckham/azure-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/shanepeckham/azure-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shanepeckham/azure-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/shanepeckham/azure-cli/languages","stargazers_url":"https://api.github.com/repos/shanepeckham/azure-cli/stargazers","contributors_url":"https://api.github.com/repos/shanepeckham/azure-cli/contributors","subscribers_url":"https://api.github.com/repos/shanepeckham/azure-cli/subscribers","subscription_url":"https://api.github.com/repos/shanepeckham/azure-cli/subscription","commits_url":"https://api.github.com/repos/shanepeckham/azure-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/shanepeckham/azure-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/shanepeckham/azure-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/shanepeckham/azure-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/shanepeckham/azure-cli/contents/{+path}","compare_url":"https://api.github.com/repos/shanepeckham/azure-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shanepeckham/azure-cli/merges","archive_url":"https://api.github.com/repos/shanepeckham/azure-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shanepeckham/azure-cli/downloads","issues_url":"https://api.github.com/repos/shanepeckham/azure-cli/issues{/number}","pulls_url":"https://api.github.com/repos/shanepeckham/azure-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/shanepeckham/azure-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/shanepeckham/azure-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shanepeckham/azure-cli/labels{/name}","releases_url":"https://api.github.com/repos/shanepeckham/azure-cli/releases{/id}","deployments_url":"https://api.github.com/repos/shanepeckham/azure-cli/deployments","created_at":"2018-07-30T11:56:26Z","updated_at":"2018-07-30T11:56:36Z","pushed_at":"2018-08-07T13:53:22Z","git_url":"git://github.com/shanepeckham/azure-cli.git","ssh_url":"git@github.com:shanepeckham/azure-cli.git","clone_url":"https://github.com/shanepeckham/azure-cli.git","svn_url":"https://github.com/shanepeckham/azure-cli","homepage":null,"size":49353,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"Azure:dev","ref":"dev","sha":"45879fcb3aa29a4e434a1d5b6a1be738db31fa69","user":{"login":"Azure","id":6844498,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NDQ0OTg=","avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":51040886,"node_id":"MDEwOlJlcG9zaXRvcnk1MTA0MDg4Ng==","name":"azure-cli","full_name":"Azure/azure-cli","owner":{"login":"Azure","id":6844498,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4NDQ0OTg=","avatar_url":"https://avatars0.githubusercontent.com/u/6844498?v=4","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/azure-cli","description":"Command-line tools for Azure.","fork":false,"url":"https://api.github.com/repos/Azure/azure-cli","forks_url":"https://api.github.com/repos/Azure/azure-cli/forks","keys_url":"https://api.github.com/repos/Azure/azure-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/azure-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/azure-cli/teams","hooks_url":"https://api.github.com/repos/Azure/azure-cli/hooks","issue_events_url":"https://api.github.com/repos/Azure/azure-cli/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/azure-cli/events","assignees_url":"https://api.github.com/repos/Azure/azure-cli/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/azure-cli/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/azure-cli/tags","blobs_url":"https://api.github.com/repos/Azure/azure-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/azure-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/azure-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/azure-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/azure-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/azure-cli/languages","stargazers_url":"https://api.github.com/repos/Azure/azure-cli/stargazers","contributors_url":"https://api.github.com/repos/Azure/azure-cli/contributors","subscribers_url":"https://api.github.com/repos/Azure/azure-cli/subscribers","subscription_url":"https://api.github.com/repos/Azure/azure-cli/subscription","commits_url":"https://api.github.com/repos/Azure/azure-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/azure-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/azure-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/azure-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/azure-cli/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/azure-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/azure-cli/merges","archive_url":"https://api.github.com/repos/Azure/azure-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/azure-cli/downloads","issues_url":"https://api.github.com/repos/Azure/azure-cli/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/azure-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/azure-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/azure-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/azure-cli/labels{/name}","releases_url":"https://api.github.com/repos/Azure/azure-cli/releases{/id}","deployments_url":"https://api.github.com/repos/Azure/azure-cli/deployments","created_at":"2016-02-04T00:21:51Z","updated_at":"2018-08-08T07:05:15Z","pushed_at":"2018-08-08T11:38:40Z","git_url":"git://github.com/Azure/azure-cli.git","ssh_url":"git@github.com:Azure/azure-cli.git","clone_url":"https://github.com/Azure/azure-cli.git","svn_url":"https://github.com/Azure/azure-cli","homepage":null,"size":49963,"stargazers_count":841,"watchers_count":841,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":529,"mirror_url":null,"archived":false,"open_issues_count":811,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":529,"open_issues":811,"watchers":841,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-cli/pulls/6975"},"html":{"href":"https://github.com/Azure/azure-cli/pull/6975"},"issue":{"href":"https://api.github.com/repos/Azure/azure-cli/issues/6975"},"comments":{"href":"https://api.github.com/repos/Azure/azure-cli/issues/6975/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/azure-cli/pulls/6975/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/azure-cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/azure-cli/pulls/6975/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/azure-cli/statuses/1a34dd9f8329bd7e25d5f7b64b82665c26af8394"}},"author_association":"NONE"}}
{"actor":{"display_login":"shanepeckham"}}