コード例 #1
0
        public virtual async Task <ClientSecretDto> AddSecretAsync(ClientSecretCreateDto clientSecretCreate)
        {
            var client = await ClientRepository.GetAsync(clientSecretCreate.ClientId);

            var clientSecretValue = clientSecretCreate.Value;

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

            var clientSecret = client.FindSecret(clientSecretValue, clientSecretCreate.Type);

            return(ObjectMapper.Map <ClientSecret, ClientSecretDto>(clientSecret));
        }
コード例 #2
0
        public virtual async Task <ClientSecretDto> AddSecretAsync(ClientSecretCreateDto clientSecretCreate)
        {
            var client = await ClientRepository.GetAsync(clientSecretCreate.ClientId);

            var clientSecretValue = clientSecretCreate.Value;

            // 如果是 SharedSecret 类型的密钥
            // 采用 IdentityServer4 服务器扩展方法加密
            if (IdentityServerConstants.SecretTypes.SharedSecret.Equals(clientSecretCreate.Type))
            {
                if (clientSecretCreate.HashType == HashType.Sha256)
                {
                    clientSecretValue = clientSecretCreate.Value.Sha256();
                }
                else if (clientSecretCreate.HashType == HashType.Sha512)
                {
                    clientSecretValue = clientSecretCreate.Value.Sha512();
                }
            }
            else
            {
                // 其他类型的服务器加密方式暂时不提供
                throw new UserFriendlyException(L["EncryptionNotImplemented", clientSecretCreate.Type]);
            }
            client.AddSecret(clientSecretValue, clientSecretCreate.Expiration,
                             clientSecretCreate.Type, clientSecretCreate.Description);

            var clientSecret = client.FindSecret(clientSecretValue, clientSecretCreate.Type);

            return(ObjectMapper.Map <ClientSecret, ClientSecretDto>(clientSecret));
        }
コード例 #3
0
 public virtual async Task <ClientSecretDto> AddSecretAsync(ClientSecretCreateDto clientSecretCreate)
 {
     return(await ClientAppService.AddSecretAsync(clientSecretCreate));
 }