示例#1
0
        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)));
        }
示例#2
0
        public async Task <IActionResult> 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.siteConfiguration, this.User);

                var identityUpdateRequest = new HttpRequestMessage(HttpMethod.Post, this.siteConfiguration.TodoListWebApiRootUrl + "api/identity");
                identityUpdateRequest.Content = new JsonContent(model);
                var todoListWebApiIdentityInfoResponse = await todoListWebApiClient.SendAsync(identityUpdateRequest);

                todoListWebApiIdentityInfoResponse.EnsureSuccessStatusCode();
            }
            return(RedirectToAction("Index"));
        }