예제 #1
0
        private async Task <string> RemoveDkpAdminAsync(string pUsername, string pUserPool)
        {
            AmazonCognitoIdentityProviderClient provider =
                new AmazonCognitoIdentityProviderClient(RegionEndpoint.USEast2);
            AdminRemoveUserFromGroupRequest vRequest = new AdminRemoveUserFromGroupRequest
            {
                GroupName  = ADMIN_GROUP,
                Username   = pUsername,
                UserPoolId = pUserPool
            };
            var vResponse = await provider.AdminRemoveUserFromGroupAsync(vRequest);

            return(vResponse.HttpStatusCode.ToString());
        }
        public async Task UpdateUserGroup(string id, string groupName)
        {
            var groupsResponse = await provider.AdminListGroupsForUserAsync(new AdminListGroupsForUserRequest
            {
                Username   = id,
                UserPoolId = Configurations.Cognito.CognitoPoolId,
            }
                                                                            );

            var userAlreadyInGroup = false;

            if (groupsResponse.Groups.Count > 0)
            {
                foreach (var group in groupsResponse.Groups)
                {
                    if (group.GroupName == groupName)
                    {
                        userAlreadyInGroup = true;
                        continue;
                    }
                    else
                    {
                        await provider.AdminRemoveUserFromGroupAsync(new AdminRemoveUserFromGroupRequest
                        {
                            Username   = id,
                            UserPoolId = Configurations.Cognito.CognitoPoolId,
                            GroupName  = group.GroupName,
                        });
                    }
                }
            }

            if (userAlreadyInGroup)
            {
                return;
            }

            var request = new AdminAddUserToGroupRequest
            {
                Username   = id,
                UserPoolId = Configurations.Cognito.CognitoPoolId,
                GroupName  = groupName,
            };

            await provider.AdminAddUserToGroupAsync(request);
        }