/// <summary> /// Gets identity information about the currently authenticated user. /// </summary> public async Task <IdentityInfo> Get() { // Retrieve identity information from the downstream Taxonomy Web API. var relatedApplicationIdentities = new List <IdentityInfo>(); try { var taxonomyWebApiClient = await CategoryController.GetTaxonomyClient(this.User); var taxonomyWebApiIdentityInfoRequest = new HttpRequestMessage(HttpMethod.Get, SiteConfiguration.TaxonomyWebApiRootUrl + "api/identity"); var taxonomyWebApiIdentityInfoResponse = await taxonomyWebApiClient.SendAsync(taxonomyWebApiIdentityInfoRequest); taxonomyWebApiIdentityInfoResponse.EnsureSuccessStatusCode(); var taxonomyWebApiIdentityInfoResponseString = await taxonomyWebApiIdentityInfoResponse.Content.ReadAsStringAsync(); var taxonomyWebApiIdentityInfo = JsonConvert.DeserializeObject <IdentityInfo>(taxonomyWebApiIdentityInfoResponseString); relatedApplicationIdentities.Add(taxonomyWebApiIdentityInfo); } catch (Exception exc) { relatedApplicationIdentities.Add(IdentityInfoFactory.FromException("Taxonomy Web API", exc)); } // Aggregate the current identity information with the downstream identities. var graphClient = default(AadGraphClient); if (StsConfiguration.StsType == StsType.AzureActiveDirectory) { graphClient = new AadGraphClient(StsConfiguration.Authority, StsConfiguration.AadTenant, SiteConfiguration.TodoListWebApiClientId, SiteConfiguration.TodoListWebApiClientSecret); } return(await IdentityInfoFactory.FromPrincipal(this.User, "Access Token", "Todo List Web API", relatedApplicationIdentities, graphClient)); }
public async Task <IActionResult> Index() { // Get identity information from the Todo List Web API. var relatedApplicationIdentities = new List <IdentityInfo>(); try { var todoListWebApiClient = await TodoListController.GetTodoListClient(this.siteConfiguration, this.User); var todoListWebApiIdentityInfoRequest = new HttpRequestMessage(HttpMethod.Get, this.siteConfiguration.TodoListWebApiRootUrl + "api/identity"); var todoListWebApiIdentityInfoResponse = await todoListWebApiClient.SendAsync(todoListWebApiIdentityInfoRequest); todoListWebApiIdentityInfoResponse.EnsureSuccessStatusCode(); var todoListWebApiIdentityInfoResponseString = await todoListWebApiIdentityInfoResponse.Content.ReadAsStringAsync(); var todoListWebApiIdentityInfo = JsonConvert.DeserializeObject <IdentityInfo>(todoListWebApiIdentityInfoResponseString); relatedApplicationIdentities.Add(todoListWebApiIdentityInfo); } catch (Exception exc) { relatedApplicationIdentities.Add(IdentityInfoFactory.FromException("Todo List Web API", exc)); } // Gather identity information from the current application and aggregate it with the identity information from the Web API. var graphClient = default(AadGraphClient); if (StsConfiguration.StsType == StsType.AzureActiveDirectory) { graphClient = new AadGraphClient(StsConfiguration.Authority, StsConfiguration.AadTenant, this.siteConfiguration.TodoListWebCoreClientId, this.siteConfiguration.TodoListWebCoreClientSecret); } var identityInfo = await IdentityInfoFactory.FromPrincipal(this.User, "ID Token", SiteConfiguration.ApplicationName, relatedApplicationIdentities, graphClient); return(View(new AccountIndexViewModel(identityInfo))); }
protected async void Page_Load(object sender, EventArgs e) { // Get identity information from the Todo List Web API. var relatedApplicationIdentities = new List <IdentityInfo>(); try { var todoListWebApiClient = await GetTodoListClient(this.User); var todoListWebApiIdentityInfoRequest = new HttpRequestMessage(HttpMethod.Get, SiteConfiguration.TodoListWebApiRootUrl + "api/identity"); var todoListWebApiIdentityInfoResponse = await todoListWebApiClient.SendAsync(todoListWebApiIdentityInfoRequest); todoListWebApiIdentityInfoResponse.EnsureSuccessStatusCode(); var todoListWebApiIdentityInfoResponseString = await todoListWebApiIdentityInfoResponse.Content.ReadAsStringAsync(); var todoListWebApiIdentityInfo = JsonConvert.DeserializeObject <IdentityInfo>(todoListWebApiIdentityInfoResponseString); relatedApplicationIdentities.Add(todoListWebApiIdentityInfo); } catch (Exception exc) { relatedApplicationIdentities.Add(IdentityInfoFactory.FromException("Todo List Web API", exc)); } // Gather identity information from the current application and aggregate it with the identity information from the Web API. var graphClient = default(AadGraphClient); if (StsConfiguration.StsType == StsType.AzureActiveDirectory) { graphClient = new AadGraphClient(StsConfiguration.Authority, StsConfiguration.AadTenant, SiteConfiguration.TodoListWebFormsClientId, SiteConfiguration.TodoListWebFormsClientSecret); } this.identity = await IdentityInfoFactory.FromPrincipal(this.User, "ID Token", SiteConfiguration.ApplicationName, relatedApplicationIdentities, graphClient); }