public virtual ApiResourceSecretsDto BuildApiSecretsViewModel(ApiResourceSecretsDto apiSecrets)
        {
            apiSecrets.HashTypes = ClientService.GetHashTypes();
            apiSecrets.TypeList  = ClientService.GetSecretTypes();

            return(apiSecrets);
        }
Exemple #2
0
        public async Task <IActionResult> ApiSecretDelete(ApiResourceSecretsDto apiSecret)
        {
            await _apiResourceService.DeleteApiResourceSecretAsync(apiSecret);

            SuccessNotification(_localizer["SuccessDeleteApiSecret"], _localizer["SuccessTitle"]);

            return(RedirectToAction(nameof(ApiSecrets), new { Id = apiSecret.ApiResourceId }));
        }
        public virtual async Task <int> DeleteApiResourceSecretAsync(ApiResourceSecretsDto apiSecret)
        {
            var secret = apiSecret.ToEntity();

            var deleted = await ApiResourceRepository.DeleteApiResourceSecretAsync(secret);

            await AuditEventLogger.LogEventAsync(new ApiSecretDeletedEvent(apiSecret.ApiResourceId, apiSecret.ApiSecretId));

            return(deleted);
        }
        public virtual async Task <int> AddApiResourceSecretAsync(ApiResourceSecretsDto apiSecret)
        {
            HashApiSharedSecret(apiSecret);

            var secret = apiSecret.ToEntity();

            var added = await ApiResourceRepository.AddApiResourceSecretAsync(apiSecret.ApiResourceId, secret);

            await AuditEventLogger.LogEventAsync(new ApiSecretAddedEvent(apiSecret.ApiResourceId, apiSecret.Type, apiSecret.Expiration));

            return(added);
        }
Exemple #5
0
        public async Task <IActionResult> ApiSecrets(ApiResourceSecretsDto apiSecret)
        {
            if (!ModelState.IsValid)
            {
                return(View(apiSecret));
            }

            await _apiResourceService.AddApiResourceSecretAsync(apiSecret);

            SuccessNotification(_localizer["SuccessAddApiSecret"], _localizer["SuccessTitle"]);

            return(RedirectToAction(nameof(ApiSecrets), new { Id = apiSecret.ApiResourceId }));
        }
        private void HashApiSharedSecret(ApiResourceSecretsDto apiSecret)
        {
            if (apiSecret.Type != SharedSecret)
            {
                return;
            }

            if (apiSecret.Type == ((int)HashType.Sha256).ToString())
            {
                apiSecret.Value = apiSecret.Value.Sha256();
            }
            else if (apiSecret.Type == ((int)HashType.Sha512).ToString())
            {
                apiSecret.Value = apiSecret.Value.Sha512();
            }
        }
 public static ApiResourceSecret ToEntity(this ApiResourceSecretsDto resource)
 {
     return(resource == null ? null : Mapper.Map <ApiResourceSecret>(resource));
 }