public async Task <InvokeResult> AddClientAppAsync(ClientApp clientApp, EntityHeader org, EntityHeader user) { ValidationCheck(clientApp, Actions.Create); await AuthorizeAsync(clientApp, AuthorizeResult.AuthorizeActions.Create, user, org); var primaryAddResult = await _secureStorage.AddSecretAsync(org, clientApp.AppAuthKeyPrimary); if (!primaryAddResult.Successful) { return(primaryAddResult.ToInvokeResult()); } var secondaryAddResult = await _secureStorage.AddSecretAsync(org, clientApp.AppAuthKeySecondary); if (!secondaryAddResult.Successful) { return(secondaryAddResult.ToInvokeResult()); } clientApp.AppAuthKeyPrimarySecureId = primaryAddResult.Result; clientApp.AppAuthKeyPrimary = null; clientApp.AppAuthKeySecondarySecureId = secondaryAddResult.Result; clientApp.AppAuthKeySecondary = null; var clientAppUserId = Guid.NewGuid().ToId(); clientApp.ClientAppUser = EntityHeader.Create(clientAppUserId, $"{clientApp.Key} Service Account"); var fullOrg = await _orgManager.GetOrganizationAsync(org.Id, org, user); var clientAppEmail = $"{fullOrg.Namespace}.{clientApp.Key}@nodomain.cantlogin"; var result = await _userManager.CreateAsync(new UserAdmin.Models.Users.AppUser() { CurrentOrganization = org, Email = clientAppEmail, FirstName = clientApp.Name, LastName = "Service Account", Id = clientAppUserId, UserName = clientAppEmail, OwnerOrganization = org, IsAppBuilder = true, IsOrgAdmin = false, IsSystemAdmin = false, IsRuntimeuser = true, PhoneNumberConfirmed = true, EmailConfirmed = true, CreationDate = clientApp.CreationDate, LastUpdatedDate = clientApp.CreationDate, LastUpdatedBy = user, CreatedBy = user, IsAccountDisabled = false, Name = clientApp.ClientAppUser.Text, PhoneNumber = "612 555-1212", }, $"NuvI0Tabc{Guid.NewGuid().ToId()}"); if (!result.Successful) { return(result); } await _orgManager.AddUserToOrgAsync(org.Id, clientAppUserId, org, user); await _repo.AddClientAppAsync(clientApp); return(InvokeResult.Success); }
public async Task <DetailResponse <Organization> > GetOrgAsync(string id) { var org = await _orgManager.GetOrganizationAsync(id, OrgEntityHeader, UserEntityHeader); return(DetailResponse <Organization> .Create(org)); }