/// <summary>
        /// Update User
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public async Task UpdateUserAsync(UserInfo userInfo)
        {
            AdminUpdateUserAttributesRequest updateUserAttributesRequest = new AdminUpdateUserAttributesRequest()
            {
                Username       = userInfo.UserName,
                UserPoolId     = _appConfigInfo.AWSPoolId,
                UserAttributes = new List <AttributeType>()
                {
                    new AttributeType()
                    {
                        Name  = "custom:Role",
                        Value = userInfo.Role
                    },
                    new AttributeType()
                    {
                        Name  = "custom:Groups",
                        Value = string.Join(",", userInfo.Groups)
                    }
                }
            };

            try
            {
                var userCreateResult = await _provider.AdminUpdateUserAttributesAsync(updateUserAttributesRequest);
            }
            catch (UserNotFoundException)
            {
                throw new CcsSsoException("USERNAME_NOT_EXISTS");
            }
        }
Ejemplo n.º 2
0
        public bool UpdateAttributes(ApiUpdateRequest updateInfo)
        {
            using AmazonCognitoIdentityProviderClient userProvider = GetCognitoIdentityProvider();
            var request = new AdminUpdateUserAttributesRequest();

            request.Username       = updateInfo.UserName;
            request.UserPoolId     = CognitoSettings.Values.UserPoolId;
            request.UserAttributes = updateInfo.Attributes.Select(data => new AttributeType()
            {
                Name  = data.Key,
                Value = data.Value
            }).ToList();
            userProvider.AdminUpdateUserAttributesAsync(request, CancellationToken.None).GetAwaiter().GetResult();
            return(true);
        }
Ejemplo n.º 3
0
        public Task <AdminUpdateUserAttributesResponse> UpdateUser(User user)
        {
            var attrs = new List <AttributeType>();

            attrs.Add(new AttributeType {
                Name  = "custom:department",
                Value = user.Department
            });
            var req = new AdminUpdateUserAttributesRequest
            {
                Username       = user.Name,
                UserPoolId     = userPoolId,
                UserAttributes = attrs
            };

            return(client.AdminUpdateUserAttributesAsync(req));
        }
        public void OnPostCreateClaim()
        {
            List <AttributeType> att = new List <AttributeType>();

            att.Add(new AttributeType()
            {
                Name = CustomClaim.Key, Value = CustomClaim.Value
            });
            try
            {
                AdminUpdateUserAttributesRequest updateRequest = new AdminUpdateUserAttributesRequest();
                updateRequest.Username       = UserInfo.Username;
                updateRequest.UserPoolId     = _userPool.PoolID;
                updateRequest.UserAttributes = att;

                var res = _identityProvider.AdminUpdateUserAttributesAsync(updateRequest).Result;
                if (res.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    Message = "Successfully added the new attribute";
                }

                var newUserInfo = _identityProvider.AdminGetUserAsync(new AdminGetUserRequest()
                {
                    Username = UserInfo.Username, UserPoolId = _userPool.PoolID
                }).Result;
                Message = "Found a user";
                UserInfoSet ui = new UserInfoSet();
                ui.Username = newUserInfo.Username;
                List <KeyValuePair <string, string> > newAtt = new List <KeyValuePair <string, string> >();
                foreach (var a in newUserInfo.UserAttributes)
                {
                    newAtt.Add(new KeyValuePair <string, string>(a.Name, a.Value));
                }
                ui.Attributes  = newAtt;
                ui.IsEnabled   = newUserInfo.Enabled;
                ui.CreatedDate = newUserInfo.UserCreateDate;
                UserInfo       = ui;
            }catch (System.AggregateException ex)
            {
                Message = ex.Message;
            }

            Console.WriteLine("test");
        }
        public async Task UpdateUser(string id, Dictionary <string, string> attributes, bool setEable = false)
        {
            if (attributes.Count > 0)
            {
                var list = attributes.Select(x => new AttributeType {
                    Name = x.Key, Value = x.Value
                }).ToList();
                var request = new AdminUpdateUserAttributesRequest
                {
                    UserPoolId     = Configurations.Cognito.CognitoPoolId,
                    Username       = id,
                    UserAttributes = list,
                };

                await provider.AdminUpdateUserAttributesAsync(request);
            }

            if (setEable)
            {
                await SetAccountEable(id, true);
            }
        }
Ejemplo n.º 6
0
        public async Task <HttpStatusCode> AdminUpdateUserAttributesAsync(Profile profile)
        {
            var request = new AdminUpdateUserAttributesRequest
            {
                UserPoolId     = _cognito.UserPool.Id,
                Username       = $"{profile.Email}",
                UserAttributes = profile.GetCognitoAttributes().ToList()
            };

            AdminUpdateUserAttributesResponse response;

            try
            {
                response = await _provider.AdminUpdateUserAttributesAsync(request);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception: {e}");
                throw new Exception();
            }

            return(response.HttpStatusCode);
        }
 public void AdminUpdateUserAttributesAsync(AdminUpdateUserAttributesRequest request, AmazonServiceCallback <AdminUpdateUserAttributesRequest, AdminUpdateUserAttributesResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 8
0
        public async void SignUpNewUser(string email, string password, string familyName, string firstName, string phoneNumber, string deviceId)
        {
            AnonymousAWSCredentials             credentials = new AnonymousAWSCredentials();
            AmazonCognitoIdentityProviderClient provider    = new AmazonCognitoIdentityProviderClient(credentials, Amazon.RegionEndpoint.USEast2);

            CognitoUserPool pool = new CognitoUserPool(ConfigurationManager.AppSettings["USERPOOL_ID"], ConfigurationManager.AppSettings["CLIENT_ID"], provider, "");

            // Based on latest user pool API
            // https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html
            // https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_VerificationMessageTemplateType.html

            // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html

            Dictionary <string, string> userAttributes = new Dictionary <string, string>(StringComparer.Ordinal)
            {
                { "email", email },
                { "family_name", familyName },
                { "given_name", firstName },
            };
            Dictionary <string, string> validationData = new Dictionary <string, string>(StringComparer.Ordinal)
            {
                { "email", email }
            };

            await pool.SignUpAsync(email, password, userAttributes, validationData).ConfigureAwait(false);

            //Get the UsersVerificationCode programatically.
            Task <AdminConfirmSignUpResponse> myresponse = provider.AdminConfirmSignUpAsync(new AdminConfirmSignUpRequest {
                UserPoolId = ConfigurationManager.AppSettings["USERPOOL_ID"], Username = email
            });


            AdminUpdateUserAttributesRequest i = new AdminUpdateUserAttributesRequest();

            i.UserAttributes.Add(new AttributeType {
                Name = "email_verified", Value = "true"
            });
            i.UserPoolId = ConfigurationManager.AppSettings["USERPOOL_ID"];
            i.Username   = email;


            AdminUpdateUserAttributesResponse T = await provider.AdminUpdateUserAttributesAsync(i);

            Debug.Print(T.ToString());
            //          client.adminUpdateUserAttributes({
            //          UserAttributes:
            //              [{
            //              Name: 'phone_number_verified',
            //    Value: 'true'
            //            }, {
            //              Name: 'email_verified',
            //    Value: 'true'
            //           }
            //  // other user attributes like phone_number or email themselves, etc
            //],
            //UserPoolId: 'COGNITO_USER_POOL_ID_HERE',
            //Username: '******'


            //myresponse.res.
            // Debug.Print(myresponse.Result.ToString());
        }