Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            await LoadAsync(user);


            return(Page());
        }
Ejemplo n.º 2
0
        /*public async Task<IActionResult> OnGetAsync()
         * {
         *  var user = await _userManager.GetUserAsync(User);
         *
         *  user.Attributes[CognitoAttribute.Address.AttributeName] = "ssssss";
         *  //await user.UpdateAttributesAsync(user.Attributes);
         *  var result = await _userManager.UpdateAsync(user);
         *  Console.WriteLine("cool");
         *  if (user == null)
         *  {
         *      return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
         *  }
         * Input = new AccountModel()
         *  {
         *      Address = user.Attributes[CognitoAttribute.Address.AttributeName]
         *  };
         *
         *
         *
         *
         *  return Page();
         * }*/
        public async Task <IActionResult> OnGetAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            await LoadAsync(user);

            //user.Attributes.Add(CognitoAttribute.Address.AttributeName, "2251 pimmit dr");
            return(Page());
        }
        private async Task <HttpClient> ConstructHttpClient()
        {
            var authState = await _authenticationStateProvider.GetAuthenticationStateAsync();

            var user = authState.User;

            if (!user.Identity.IsAuthenticated)
            {
                throw new Exception();
            }

            var userId = _cognitoUserManager.GetUserId(user);

            if (string.IsNullOrEmpty(userId))
            {
                throw new Exception();
            }

            var cognitoUser = await _cognitoUserManager.FindByIdAsync(userId);

            if (string.IsNullOrEmpty(cognitoUser?.SessionTokens.IdToken))
            {
                throw new Exception();
            }


            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization =
                AuthenticationHeaderValue.Parse($"bearer {cognitoUser.SessionTokens.IdToken}");


            return(httpClient);
        }
        public async Task <ICommunicationClient> CreateCommunicationClient(CancellationToken token)
        {
            var authState = await _authenticationStateProvider.GetAuthenticationStateAsync();

            var user = authState.User;

            if (!user.Identity.IsAuthenticated)
            {
                throw new Exception();
            }

            var userId = _cognitoUserManager.GetUserId(user);

            if (string.IsNullOrEmpty(userId))
            {
                throw new Exception();
            }

            var cognitoUser = await _cognitoUserManager.FindByIdAsync(userId);

            if (string.IsNullOrEmpty(cognitoUser?.SessionTokens.IdToken))
            {
                throw new Exception();
            }


            var cws = new ClientWebSocket();

            cws.Options.SetRequestHeader("Authorization", cognitoUser.SessionTokens.IdToken);
            await cws.ConnectAsync(new Uri(_appOptions.ImageRecognitionWebSocketAPI), token);

            return(new CommunicationClient(cws));
        }