public async Task <bool> Execute(UpdateClientParameter updateClientParameter) { if (updateClientParameter == null) { throw new ArgumentNullException(nameof(updateClientParameter)); } var existedClient = await _clientRepository.GetClientByIdAsync(updateClientParameter.ClientId); if (existedClient == null) { throw new IdentityServerManagerException(ErrorCodes.InvalidParameterCode, string.Format(ErrorDescriptions.TheClientDoesntExist, updateClientParameter.ClientId)); } SimpleIdentityServer.Core.Models.Client client = null; try { client = _generateClientFromRegistrationRequest.Execute(updateClientParameter); } catch (IdentityServerException ex) { throw new IdentityServerManagerException(ex.Code, ex.Message); } client.ClientId = existedClient.ClientId; client.AllowedScopes = updateClientParameter.AllowedScopes == null ? new List <Scope>() : updateClientParameter.AllowedScopes.Select(s => new Scope { Name = s }).ToList(); return(await _clientRepository.UpdateAsync(client)); }
public async Task <bool> Execute(UpdateClientParameter updateClientParameter) { if (updateClientParameter == null) { throw new ArgumentNullException(nameof(updateClientParameter)); } if (string.IsNullOrWhiteSpace(updateClientParameter.ClientId)) { throw new IdentityServerManagerException(ErrorCodes.InvalidParameterCode, string.Format(ErrorDescriptions.MissingParameter, "client_id")); } _managerEventSource.StartToUpdateClient(JsonConvert.SerializeObject(updateClientParameter)); var existedClient = await _clientRepository.GetClientByIdAsync(updateClientParameter.ClientId); if (existedClient == null) { throw new IdentityServerManagerException(ErrorCodes.InvalidParameterCode, string.Format(ErrorDescriptions.TheClientDoesntExist, updateClientParameter.ClientId)); } SimpleIdentityServer.Core.Common.Models.Client client = null; try { client = _generateClientFromRegistrationRequest.Execute(updateClientParameter); } catch (IdentityServerException ex) { throw new IdentityServerManagerException(ex.Code, ex.Message); } client.ClientId = existedClient.ClientId; client.AllowedScopes = updateClientParameter.AllowedScopes == null ? new List <Scope>() : updateClientParameter.AllowedScopes.Select(s => new Scope { Name = s }).ToList(); var existingScopes = await _scopeRepository.SearchByNamesAsync(client.AllowedScopes.Select(s => s.Name)); var notSupportedScopes = client.AllowedScopes.Where(s => !existingScopes.Any(sc => sc.Name == s.Name)).Select(s => s.Name); if (notSupportedScopes.Any()) { throw new IdentityServerManagerException(ErrorCodes.InvalidParameterCode, string.Format(ErrorDescriptions.TheScopesDontExist, string.Join(",", notSupportedScopes))); } var result = await _clientRepository.UpdateAsync(client); if (!result) { throw new IdentityServerManagerException(ErrorCodes.InternalErrorCode, ErrorDescriptions.TheClientCannotBeUpdated); } _managerEventSource.FinishToUpdateClient(JsonConvert.SerializeObject(updateClientParameter)); return(result); }
public void When_Passing_Null_Parameter_Then_Exception_Is_Thrown() { // ARRANGE InitializeFakeObjects(); // ACT & ASSERT Assert.Throws <ArgumentNullException>(() => _generateClientFromRegistrationRequest.Execute(null)); }
public async Task <ClientRegistrationResponse> Execute(RegistrationParameter registrationParameter) { if (registrationParameter == null) { throw new ArgumentNullException(nameof(registrationParameter)); } _simpleIdentityServerEventSource.StartRegistration(registrationParameter.ClientName); var client = _generateClientFromRegistrationRequest.Execute(registrationParameter); client.AllowedScopes = new List <Scope> { Constants.StandardScopes.OpenId, Constants.StandardScopes.ProfileScope, Constants.StandardScopes.Address, Constants.StandardScopes.Email, Constants.StandardScopes.Phone }; var clientId = Guid.NewGuid().ToString(); if (string.IsNullOrWhiteSpace(client.ClientName)) { client.ClientName = "Unknown " + clientId; } var result = new ClientRegistrationResponse { ClientId = clientId, ClientSecretExpiresAt = 0, ClientIdIssuedAt = DateTime.UtcNow.ConvertToUnixTimestamp().ToString(CultureInfo.InvariantCulture), ApplicationType = Enum.GetName(typeof(ApplicationTypes), client.ApplicationType), ClientUri = GetDefaultValue(client.ClientUri), ClientName = GetDefaultValue(client.ClientName), Contacts = GetDefaultValues(client.Contacts).ToArray(), DefaultAcrValues = GetDefaultValue(client.DefaultAcrValues), GrantTypes = client.GrantTypes == null ? new string[0] : client.GrantTypes.Select(g => Enum.GetName(typeof(GrantType), g)).ToArray(), DefaultMaxAge = client.DefaultMaxAge, IdTokenEncryptedResponseAlg = GetDefaultValue(client.IdTokenEncryptedResponseAlg), IdTokenEncryptedResponseEnc = GetDefaultValue(client.IdTokenEncryptedResponseEnc), JwksUri = GetDefaultValue(client.JwksUri), RequestObjectEncryptionAlg = GetDefaultValue(client.RequestObjectEncryptionAlg), RequestObjectEncryptionEnc = GetDefaultValue(client.RequestObjectEncryptionEnc), IdTokenSignedResponseAlg = GetDefaultValue(client.IdTokenSignedResponseAlg), LogoUri = GetDefaultValue(client.LogoUri), Jwks = registrationParameter.Jwks, RequireAuthTime = client.RequireAuthTime, InitiateLoginUri = GetDefaultValue(client.InitiateLoginUri), PolicyUri = GetDefaultValue(client.PolicyUri), RequestObjectSigningAlg = GetDefaultValue(client.RequestObjectSigningAlg), UserInfoEncryptedResponseAlg = GetDefaultValue(client.UserInfoEncryptedResponseAlg), UserInfoEncryptedResponseEnc = GetDefaultValue(client.UserInfoEncryptedResponseEnc), UserInfoSignedResponseAlg = GetDefaultValue(client.UserInfoSignedResponseAlg), TosUri = GetDefaultValue(client.TosUri), SectorIdentifierUri = GetDefaultValue(client.SectorIdentifierUri), SubjectType = GetDefaultValue(client.SubjectType), ResponseTypes = client.ResponseTypes == null ? new string[0] : client.ResponseTypes.Select(r => Enum.GetName(typeof(ResponseType), r)).ToArray(), RequestUris = GetDefaultValues(client.RequestUris).ToList(), RedirectUris = GetDefaultValues(client.RedirectionUrls).ToArray(), TokenEndpointAuthSigningAlg = GetDefaultValue(client.TokenEndPointAuthSigningAlg), TokenEndpointAuthMethod = Enum.GetName(typeof(TokenEndPointAuthenticationMethods), client.TokenEndPointAuthMethod), ScimProfile = client.ScimProfile }; if (client.TokenEndPointAuthMethod != TokenEndPointAuthenticationMethods.private_key_jwt) { result.ClientSecret = Guid.NewGuid().ToString(); client.Secrets = new List <ClientSecret> { new ClientSecret { Type = ClientSecretTypes.SharedSecret, Value = _encryptedPasswordFactory.Encrypt(result.ClientSecret) } }; } client.ClientId = result.ClientId; await _clientRepository.InsertAsync(client); _simpleIdentityServerEventSource.EndRegistration(result.ClientId, client.ClientName); return(result); }