public virtual async Task <ClientSecretDto> UpdateSecretAsync(ClientSecretUpdateDto clientSecretUpdate)
        {
            var client = await ClientRepository.GetAsync(clientSecretUpdate.ClientId);

            var clientSecret = client.ClientSecrets
                               .FirstOrDefault(secret => secret.Type.Equals(clientSecretUpdate.Type));

            if (clientSecret == null)
            {
                throw new UserFriendlyException(
                          L[AbpIdentityServerErrorConsts.ClientSecretNotFound, clientSecretUpdate.Type]);
            }
            var clientSecretValue = clientSecret.Value;

            // 如果是 SharedSecret 类型的密钥
            // 采用 IdentityServer4 服务器扩展方法加密
            if (IdentityServerConstants.SecretTypes.SharedSecret.Equals(clientSecretUpdate.Type))
            {
                if (clientSecretUpdate.HashType == HashType.Sha256)
                {
                    clientSecretValue = clientSecretUpdate.Value.Sha256();
                }
                else if (clientSecretUpdate.HashType == HashType.Sha512)
                {
                    clientSecretValue = clientSecretUpdate.Value.Sha512();
                }
            }
            else
            {
                clientSecretValue = EncryptionService.Encrypt(clientSecretUpdate.Value);
            }
            clientSecret.Value = clientSecretValue;

            return(ObjectMapper.Map <ClientSecret, ClientSecretDto>(clientSecret));
        }
Exemple #2
0
 public virtual async Task <ClientSecretDto> UpdateSecretAsync(ClientSecretUpdateDto clientSecretUpdate)
 {
     return(await ClientAppService.UpdateSecretAsync(clientSecretUpdate));
 }