Ejemplo n.º 1
0
        private async Task <string> AddDkpAdminAsync(string pUsername, string pUserPool)
        {
            AmazonCognitoIdentityProviderClient provider =
                new AmazonCognitoIdentityProviderClient(RegionEndpoint.USEast2);
            AdminAddUserToGroupRequest vRequest = new AdminAddUserToGroupRequest
            {
                GroupName  = ADMIN_GROUP,
                Username   = pUsername,
                UserPoolId = pUserPool
            };
            var vResponse = await provider.AdminAddUserToGroupAsync(vRequest);

            return(vResponse.HttpStatusCode.ToString());
        }
 public void AddUsertoGroup(string username, string groupname)
 {
     try
     {
         var addUserToGroup = new AdminAddUserToGroupRequest {
             GroupName = groupname, Username = username, UserPoolId = _poolId
         };
         _client.AdminAddUserToGroup(new AdminAddUserToGroupRequest());
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        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);
        }
Ejemplo n.º 4
0
        public async Task AddUserToGroup(string Username, string GroupName)
        {
            AdminAddUserToGroupRequest request = new AdminAddUserToGroupRequest()
            {
                GroupName  = GroupName,
                Username   = Username,
                UserPoolId = GetUserPoolId(),
            };

            AmazonCognitoIdentityProviderClient identityProvider = GetAmazonCognitoIdentity();
            AdminAddUserToGroupResponse         response         = await identityProvider.AdminAddUserToGroupAsync(request);

            if (!response.HttpStatusCode.Equals(HttpStatusCode.OK))
            {
                throw new WebApiException(response.HttpStatusCode, "add user to group failed");
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <string> > Register(UserVM user)
        {
            var cognito = new AmazonCognitoIdentityProviderClient(_region);

            var signUpRequest = new SignUpRequest
            {
                ClientId = _clientId,
                Password = user.Password,
                Username = user.Username
            };

            var emailAttribute = new AttributeType
            {
                Name  = "email",
                Value = user.Email
            };

            signUpRequest.UserAttributes.Add(emailAttribute);


            var addToGroupRequest = new AdminAddUserToGroupRequest
            {
                GroupName  = _defaultRole,
                Username   = user.Username,
                UserPoolId = _poolId
            };

            var signUpResponse = await cognito.SignUpAsync(signUpRequest);

            var addToGroupResponse = await cognito.AdminAddUserToGroupAsync(addToGroupRequest);

            if (signUpResponse.HttpStatusCode == HttpStatusCode.OK)
            {
                _userRepository.CreateUser(user);
            }

            return(Ok());
        }
 public void AdminAddUserToGroupAsync(AdminAddUserToGroupRequest request, AmazonServiceCallback <AdminAddUserToGroupRequest, AdminAddUserToGroupResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }