Example #1
0
        public async Task <IActionResult> Put(Guid organizationId, Guid id, [FromBody] ScimUserRequestModel model)
        {
            var orgUser = await _organizationUserRepository.GetByIdAsync(id);

            if (orgUser == null || orgUser.OrganizationId != organizationId)
            {
                return(new NotFoundObjectResult(new ScimErrorResponseModel
                {
                    Status = 404,
                    Detail = "User not found."
                }));
            }

            if (model.Active && orgUser.Status == OrganizationUserStatusType.Revoked)
            {
                await _organizationService.RestoreUserAsync(orgUser, null, _userService);
            }
            else if (!model.Active && orgUser.Status != OrganizationUserStatusType.Revoked)
            {
                await _organizationService.RevokeUserAsync(orgUser, null);
            }

            // Have to get full details object for response model
            var orgUserDetails = await _organizationUserRepository.GetDetailsByIdAsync(id);

            return(new ObjectResult(new ScimUserResponseModel(orgUserDetails)));
        }
Example #2
0
        public async Task <IActionResult> Delete(Guid organizationId, Guid id, [FromBody] ScimUserRequestModel model)
        {
            var orgUser = await _organizationUserRepository.GetByIdAsync(id);

            if (orgUser == null || orgUser.OrganizationId != organizationId)
            {
                return(new NotFoundObjectResult(new ScimErrorResponseModel
                {
                    Status = 404,
                    Detail = "User not found."
                }));
            }
            await _organizationService.DeleteUserAsync(organizationId, id, null);

            return(new NoContentResult());
        }
Example #3
0
        public async Task <IActionResult> Post(Guid organizationId, [FromBody] ScimUserRequestModel model)
        {
            var email = model.PrimaryEmail?.ToLowerInvariant();

            if (string.IsNullOrWhiteSpace(email))
            {
                switch (_scimContext.RequestScimProvider)
                {
                case ScimProviderType.AzureAd:
                    email = model.UserName?.ToLowerInvariant();
                    break;

                default:
                    break;
                }
            }

            if (string.IsNullOrWhiteSpace(email) || !model.Active)
            {
                return(new BadRequestResult());
            }

            var orgUsers = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(organizationId);

            var orgUserByEmail = orgUsers.FirstOrDefault(ou => ou.Email?.ToLowerInvariant() == email);

            if (orgUserByEmail != null)
            {
                return(new ConflictResult());
            }

            string externalId = null;

            if (!string.IsNullOrWhiteSpace(model.ExternalId))
            {
                externalId = model.ExternalId;
            }
            else if (!string.IsNullOrWhiteSpace(model.UserName))
            {
                externalId = model.UserName;
            }
            else
            {
                externalId = CoreHelpers.RandomString(15);
            }

            var orgUserByExternalId = orgUsers.FirstOrDefault(ou => ou.ExternalId == externalId);

            if (orgUserByExternalId != null)
            {
                return(new ConflictResult());
            }

            var invitedOrgUser = await _organizationService.InviteUserAsync(organizationId, null, email,
                                                                            OrganizationUserType.User, false, externalId, new List <SelectionReadOnly>());

            var orgUser = await _organizationUserRepository.GetDetailsByIdAsync(invitedOrgUser.Id);

            var response = new ScimUserResponseModel(orgUser);

            return(new CreatedResult(Url.Action(nameof(Get), new { orgUser.OrganizationId, orgUser.Id }), response));
        }