{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/fhir-server/pulls/comments/241856987","pull_request_review_id":185242230,"id":241856987,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MTg1Njk4Nw==","diff_hunk":"@@ -0,0 +1,355 @@\n+// -------------------------------------------------------------------------------------------------\n+// Copyright (c) Microsoft Corporation. All rights reserved.\n+// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.\n+// -------------------------------------------------------------------------------------------------\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Linq;\n+using System.Net.Http;\n+using System.Text;\n+using System.Threading.Tasks;\n+using EnsureThat;\n+using Microsoft.AspNetCore.Http;\n+using Microsoft.AspNetCore.Mvc;\n+using Microsoft.Extensions.Configuration;\n+using Microsoft.Extensions.Logging;\n+using Microsoft.Extensions.Options;\n+using Microsoft.Health.Fhir.Core.Configs;\n+using Microsoft.Health.Fhir.Core.Exceptions;\n+using Newtonsoft.Json.Linq;\n+\n+namespace Microsoft.Health.Fhir.Api.Controllers\n+{\n+    /// <summary>\n+    /// Controller class enabling Azure Active Directory SMART on FHIR Proxy Capability\n+    /// </summary>\n+    [Route(\"/AadProxy\")]\n+    public class AadProxyController : Controller\n+    {\n+        private readonly SecurityConfiguration _securityConfiguration;\n+        private readonly bool _isAadV2;\n+        private readonly ILogger<SecurityConfiguration> _logger;\n+        private readonly IHttpClientFactory _httpClientFactory;\n+        private readonly string _aadAuthorizeEndpoint;\n+        private readonly string _aadTokenEndpoint;\n+\n+        // TODO: _launchContextFields contain a list of fields that we will transmit as part of launch context, should be configurable\n+        private readonly string[] _launchContextFields = { \"patient\", \"encounter\", \"practitioner\", \"need_patient_banner\", \"smart_style_url\" };\n+\n+        /// <summary>\n+        /// Initializes a new instance of the <see cref=\"AadProxyController\" /> class.\n+        /// </summary>\n+        /// <param name=\"securityConfiguration\">Security configuration parameters.</param>\n+        /// <param name=\"httpClientFactory\">HTTP Client Factory.</param>\n+        /// <param name=\"logger\">The logger.</param>\n+        public AadProxyController(IOptions<SecurityConfiguration> securityConfiguration, IHttpClientFactory httpClientFactory, ILogger<SecurityConfiguration> logger)\n+        {\n+            EnsureArg.IsNotNull(securityConfiguration, nameof(securityConfiguration));\n+\n+            _securityConfiguration = securityConfiguration.Value;\n+            _isAadV2 = new Uri(_securityConfiguration.Authentication.Authority).Segments.Contains(\"v2.0\");\n+            _logger = logger;\n+            _httpClientFactory = httpClientFactory;\n+\n+            var openIdConfigurationUrl = $\"{_securityConfiguration.Authentication.Authority}/.well-known/openid-configuration\";\n+\n+            HttpResponseMessage openIdConfigurationResponse;\n+            using (var httpClient = httpClientFactory.CreateClient())\n+            {\n+                try\n+                {\n+                    openIdConfigurationResponse = httpClient.GetAsync(new Uri(openIdConfigurationUrl)).GetAwaiter().GetResult();\n+                }\n+                catch (Exception ex)","path":"src/Microsoft.Health.Fhir.Api/Controllers/AadProxyController.cs","position":64,"original_position":64,"commit_id":"5ad17fd78bc63228838c4c841fa49c8e8dfe8118","original_commit_id":"5ad17fd78bc63228838c4c841fa49c8e8dfe8118","user":{"login":"johnstairs","id":339432,"node_id":"MDQ6VXNlcjMzOTQzMg==","avatar_url":"https://avatars3.githubusercontent.com/u/339432?v=4","gravatar_id":"","url":"https://api.github.com/users/johnstairs","html_url":"https://github.com/johnstairs","followers_url":"https://api.github.com/users/johnstairs/followers","following_url":"https://api.github.com/users/johnstairs/following{/other_user}","gists_url":"https://api.github.com/users/johnstairs/gists{/gist_id}","starred_url":"https://api.github.com/users/johnstairs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnstairs/subscriptions","organizations_url":"https://api.github.com/users/johnstairs/orgs","repos_url":"https://api.github.com/users/johnstairs/repos","events_url":"https://api.github.com/users/johnstairs/events{/privacy}","received_events_url":"https://api.github.com/users/johnstairs/received_events","type":"User","site_admin":false},"body":"We should avoid catching all exceptions types. ","created_at":"2018-12-14T19:00:54Z","updated_at":"2018-12-14T19:01:01Z","html_url":"https://github.com/Microsoft/fhir-server/pull/268#discussion_r241856987","pull_request_url":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/fhir-server/pulls/comments/241856987"},"html":{"href":"https://github.com/Microsoft/fhir-server/pull/268#discussion_r241856987"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268","id":237092736,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM3MDkyNzM2","html_url":"https://github.com/Microsoft/fhir-server/pull/268","diff_url":"https://github.com/Microsoft/fhir-server/pull/268.diff","patch_url":"https://github.com/Microsoft/fhir-server/pull/268.patch","issue_url":"https://api.github.com/repos/Microsoft/fhir-server/issues/268","number":268,"state":"open","locked":false,"title":"Personal/mihansen/aad proxy","user":{"login":"hansenms","id":1149740,"node_id":"MDQ6VXNlcjExNDk3NDA=","avatar_url":"https://avatars2.githubusercontent.com/u/1149740?v=4","gravatar_id":"","url":"https://api.github.com/users/hansenms","html_url":"https://github.com/hansenms","followers_url":"https://api.github.com/users/hansenms/followers","following_url":"https://api.github.com/users/hansenms/following{/other_user}","gists_url":"https://api.github.com/users/hansenms/gists{/gist_id}","starred_url":"https://api.github.com/users/hansenms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hansenms/subscriptions","organizations_url":"https://api.github.com/users/hansenms/orgs","repos_url":"https://api.github.com/users/hansenms/repos","events_url":"https://api.github.com/users/hansenms/events{/privacy}","received_events_url":"https://api.github.com/users/hansenms/received_events","type":"User","site_admin":false},"body":"## Description\r\nIntroduces SMART on FHIR AAD Proxy\r\n\r\n## Related issues\r\nAddresses #222 \r\n\r\n## Testing\r\nE2E Tests using Selenium Added. ","created_at":"2018-12-08T21:34:48Z","updated_at":"2018-12-14T19:01:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2b2cfba3ae4c4a97229968fc412ed736a29292d9","assignee":null,"assignees":[],"requested_reviewers":[{"login":"brendankowitz","id":197221,"node_id":"MDQ6VXNlcjE5NzIyMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/197221?v=4","gravatar_id":"","url":"https://api.github.com/users/brendankowitz","html_url":"https://github.com/brendankowitz","followers_url":"https://api.github.com/users/brendankowitz/followers","following_url":"https://api.github.com/users/brendankowitz/following{/other_user}","gists_url":"https://api.github.com/users/brendankowitz/gists{/gist_id}","starred_url":"https://api.github.com/users/brendankowitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendankowitz/subscriptions","organizations_url":"https://api.github.com/users/brendankowitz/orgs","repos_url":"https://api.github.com/users/brendankowitz/repos","events_url":"https://api.github.com/users/brendankowitz/events{/privacy}","received_events_url":"https://api.github.com/users/brendankowitz/received_events","type":"User","site_admin":false},{"login":"brandonpollett","id":18427011,"node_id":"MDQ6VXNlcjE4NDI3MDEx","avatar_url":"https://avatars2.githubusercontent.com/u/18427011?v=4","gravatar_id":"","url":"https://api.github.com/users/brandonpollett","html_url":"https://github.com/brandonpollett","followers_url":"https://api.github.com/users/brandonpollett/followers","following_url":"https://api.github.com/users/brandonpollett/following{/other_user}","gists_url":"https://api.github.com/users/brandonpollett/gists{/gist_id}","starred_url":"https://api.github.com/users/brandonpollett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandonpollett/subscriptions","organizations_url":"https://api.github.com/users/brandonpollett/orgs","repos_url":"https://api.github.com/users/brandonpollett/repos","events_url":"https://api.github.com/users/brandonpollett/events{/privacy}","received_events_url":"https://api.github.com/users/brandonpollett/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268/commits","review_comments_url":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268/comments","review_comment_url":"https://api.github.com/repos/Microsoft/fhir-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/fhir-server/issues/268/comments","statuses_url":"https://api.github.com/repos/Microsoft/fhir-server/statuses/5ad17fd78bc63228838c4c841fa49c8e8dfe8118","head":{"label":"Microsoft:personal/mihansen/aad-proxy","ref":"personal/mihansen/aad-proxy","sha":"5ad17fd78bc63228838c4c841fa49c8e8dfe8118","user":{"login":"Microsoft","id":6154722,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxNTQ3MjI=","avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":145907688,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU5MDc2ODg=","name":"fhir-server","full_name":"Microsoft/fhir-server","private":false,"owner":{"login":"Microsoft","id":6154722,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxNTQ3MjI=","avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Microsoft/fhir-server","description":"A service that implements the FHIR standard","fork":false,"url":"https://api.github.com/repos/Microsoft/fhir-server","forks_url":"https://api.github.com/repos/Microsoft/fhir-server/forks","keys_url":"https://api.github.com/repos/Microsoft/fhir-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/fhir-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/fhir-server/teams","hooks_url":"https://api.github.com/repos/Microsoft/fhir-server/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/fhir-server/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/fhir-server/events","assignees_url":"https://api.github.com/repos/Microsoft/fhir-server/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/fhir-server/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/fhir-server/tags","blobs_url":"https://api.github.com/repos/Microsoft/fhir-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/fhir-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/fhir-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/fhir-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/fhir-server/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/fhir-server/languages","stargazers_url":"https://api.github.com/repos/Microsoft/fhir-server/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/fhir-server/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/fhir-server/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/fhir-server/subscription","commits_url":"https://api.github.com/repos/Microsoft/fhir-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/fhir-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/fhir-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/fhir-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/fhir-server/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/fhir-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/fhir-server/merges","archive_url":"https://api.github.com/repos/Microsoft/fhir-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/fhir-server/downloads","issues_url":"https://api.github.com/repos/Microsoft/fhir-server/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/fhir-server/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/fhir-server/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/fhir-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/fhir-server/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/fhir-server/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/fhir-server/deployments","created_at":"2018-08-23T21:11:07Z","updated_at":"2018-12-14T15:55:37Z","pushed_at":"2018-12-14T18:51:28Z","git_url":"git://github.com/Microsoft/fhir-server.git","ssh_url":"git@github.com:Microsoft/fhir-server.git","clone_url":"https://github.com/Microsoft/fhir-server.git","svn_url":"https://github.com/Microsoft/fhir-server","homepage":null,"size":1762,"stargazers_count":110,"watchers_count":110,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"archived":false,"open_issues_count":69,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":27,"open_issues":69,"watchers":110,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"3a41ba984f0653ac58de6d54e53ff73ab9715864","user":{"login":"Microsoft","id":6154722,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxNTQ3MjI=","avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":145907688,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU5MDc2ODg=","name":"fhir-server","full_name":"Microsoft/fhir-server","private":false,"owner":{"login":"Microsoft","id":6154722,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxNTQ3MjI=","avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Microsoft/fhir-server","description":"A service that implements the FHIR standard","fork":false,"url":"https://api.github.com/repos/Microsoft/fhir-server","forks_url":"https://api.github.com/repos/Microsoft/fhir-server/forks","keys_url":"https://api.github.com/repos/Microsoft/fhir-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/fhir-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/fhir-server/teams","hooks_url":"https://api.github.com/repos/Microsoft/fhir-server/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/fhir-server/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/fhir-server/events","assignees_url":"https://api.github.com/repos/Microsoft/fhir-server/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/fhir-server/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/fhir-server/tags","blobs_url":"https://api.github.com/repos/Microsoft/fhir-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/fhir-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/fhir-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/fhir-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/fhir-server/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/fhir-server/languages","stargazers_url":"https://api.github.com/repos/Microsoft/fhir-server/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/fhir-server/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/fhir-server/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/fhir-server/subscription","commits_url":"https://api.github.com/repos/Microsoft/fhir-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/fhir-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/fhir-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/fhir-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/fhir-server/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/fhir-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/fhir-server/merges","archive_url":"https://api.github.com/repos/Microsoft/fhir-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/fhir-server/downloads","issues_url":"https://api.github.com/repos/Microsoft/fhir-server/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/fhir-server/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/fhir-server/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/fhir-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/fhir-server/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/fhir-server/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/fhir-server/deployments","created_at":"2018-08-23T21:11:07Z","updated_at":"2018-12-14T15:55:37Z","pushed_at":"2018-12-14T18:51:28Z","git_url":"git://github.com/Microsoft/fhir-server.git","ssh_url":"git@github.com:Microsoft/fhir-server.git","clone_url":"https://github.com/Microsoft/fhir-server.git","svn_url":"https://github.com/Microsoft/fhir-server","homepage":null,"size":1762,"stargazers_count":110,"watchers_count":110,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"archived":false,"open_issues_count":69,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":27,"open_issues":69,"watchers":110,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268"},"html":{"href":"https://github.com/Microsoft/fhir-server/pull/268"},"issue":{"href":"https://api.github.com/repos/Microsoft/fhir-server/issues/268"},"comments":{"href":"https://api.github.com/repos/Microsoft/fhir-server/issues/268/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/fhir-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/fhir-server/pulls/268/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/fhir-server/statuses/5ad17fd78bc63228838c4c841fa49c8e8dfe8118"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"johnstairs"}}