public async Task <IActionResult> CreateClientCredentials(CreateClientCredentialsViewModel model) { if (!ModelState.IsValid) { return(View(model)); } if (!TempData.ContainsKey(_selectedScopes)) { return(RedirectToAction(nameof(ClientCredentials))); } var selectedScopes = JsonSerializer.Deserialize <List <string> >( TempData.Peek(_selectedScopes) .ToString()); using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); var newClient = CreateBasicClientEntity(model.Name, selectedScopes); var createResult = await _identityServerRepository.CreateIdentityClientAsync(newClient); if (createResult.IsError) { scope.Dispose(); ModelState.AddModelError(string.Empty, createResult.OperationError.Message); return(View(model)); } var selectedOrganisationIds = JsonSerializer.Deserialize <List <Guid> >( TempData.Peek(_selectedOrganisationIds) .ToString()); var currentRoleUserEmail = HttpContext.Session.GetString(_roleUserEmail); var authorisedOrgIds = HttpContext.User.GetOrganisationIds(); var clientDbId = createResult.Value.Id; var linkResult = await _identityManagementRepository.LinkRoleUserToClientAsync( clientDbId, currentRoleUserEmail, selectedOrganisationIds, selectedScopes, authorisedOrgIds); if (linkResult.IsError) { scope.Dispose(); ModelState.AddModelError(string.Empty, createResult.OperationError.Message); return(View(model)); } TempData.Remove(_selectedScopes); TempData.Remove(_selectedOrganisationIds); var clientCredentials = new ClientCredentials(createResult.Value.ClientId, createResult.Value.Secret); TempData[_clientCredentials] = JsonSerializer.Serialize(clientCredentials); scope.Complete(); return(RedirectToAction(nameof(CreateClientCredentialsResult))); }
public async Task <IActionResult> CreateCodeClient(IdentityClientViewModel clientViewModel) { if (!ModelState.IsValid) { return(BadRequest()); } var newClientName = $"CodeClient-System-{Guid.NewGuid():N}"; var newClient = clientViewModel.MapToClientEntity(newClientName); var result = await _iIdentityServerRepository.CreateIdentityClientAsync(newClient); if (result.IsError) { return(StatusCode(result.OperationError.Code, new { message = result.OperationError.Message, clientId = result.Value.ClientId })); } return(CreatedAtAction(nameof(CreateCodeClient), new { secret = result.Value.Secret, clientId = result.Value.ClientId })); }