public async Task <ActionResult> Index() { // Get identity information from the Todo List Web API. var relatedApplicationIdentities = new List <IdentityInfo>(); try { var todoListWebApiClient = await TodoListController.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.TodoListWebAppClientId, SiteConfiguration.TodoListWebAppClientSecret); } var identityInfo = await IdentityInfoFactory.FromPrincipal(this.User, "ID Token", SiteConfiguration.ApplicationName, relatedApplicationIdentities, graphClient); return(View(new AccountIndexViewModel(identityInfo))); }
public async Task <ActionResult> Index(IdentityUpdate model) { if (model != null && !string.IsNullOrWhiteSpace(model.DisplayName)) { // Update identity information through the Todo List Web API. var todoListWebApiClient = await TodoListController.GetTodoListClient(this.User); var identityUpdateRequest = new HttpRequestMessage(HttpMethod.Post, SiteConfiguration.TodoListWebApiRootUrl + "api/identity"); identityUpdateRequest.Content = new JsonContent(model); var todoListWebApiIdentityInfoResponse = await todoListWebApiClient.SendAsync(identityUpdateRequest); todoListWebApiIdentityInfoResponse.EnsureSuccessStatusCode(); } return(RedirectToAction("Index")); }