public static ApiKey Create(ApiKeyDto dto)
        {
            var newApiKey = dto.ToEntity();

            db.ApiKeys.Add(newApiKey);

            db.SaveChanges();
            return(newApiKey);
        }
Exemple #2
0
        public IActionResult AddNew([FromBody] ApiKeyDto apikey)
        {
            var apiKey = new ApiKey {
                Description = apikey.Description,
                Id          = Guid.NewGuid().ToString()
            };

            _unitOfWork.ApiKeys.Add(apiKey);
            return(Ok(_mapper.Map <ApiKeyDto>(apiKey)));
        }
 public HttpResponseMessage Put(HttpRequestMessage request, ApiKeyDto dto)
 {
     try
     {
         var updatedApiKey = ApiKeyService.Update(dto);
         return(request.CreateResponse(HttpStatusCode.OK, updatedApiKey));
     }
     catch (Exception)
     {
         return(new HttpResponseMessage(HttpStatusCode.BadRequest));
     }
 }
        public async Task <IActionResult> DeleteApiKey([FromBody] ApiKeyDto apiKeyDto)
        {
            var user = await GetUser();

            var apiKey = await _unitOfWork.ApiKeys.Get(
                q => q.OwnedById == user.Id && apiKeyDto.Key == q.Key
                );

            await _unitOfWork.ApiKeys.Delete(apiKey.Id);

            _logger.LogInformation($@"api key deleted for user-email {user.Email}");
            return(Ok());
        }
        public static ApiKey Update(ApiKeyDto dto)
        {
            var apiKeyRecord = db.ApiKeys.Find(dto.Id);

            if (apiKeyRecord == null)
            {
                throw new Exception("Api Key record not found");
            }

            apiKeyRecord.Username = dto.Username;
            apiKeyRecord.isActive = dto.isActive;
            apiKeyRecord.isAdmin  = dto.isAdmin;

            db.SaveChanges();

            return(apiKeyRecord);
        }
Exemple #6
0
        public VarlikResult <ApiKeyDto> GetApiKeyByIdCoinType(string idCoinType)
        {
            var result = new VarlikResult <ApiKeyDto>();

            using (var ctx = new VarlikContext())
            {
                var fromEntity = new ApiKeyDto().FromEntity().Expand();

                result.Data = ctx.ApiKey
                              .AsExpandable()
                              .Where(l => l.IdCoinType == idCoinType)
                              .Select(fromEntity)
                              .FirstOrDefault();

                result.Success();
            }
            return(result);
        }
Exemple #7
0
        public async Task <ActionResult <CreatedApiKey> > CreateApiKey(Guid id, ApiKeyDto dto, [FromServices] IApiKeyGenerator apiKeyGenerator, [FromServices] IMeansValueHasher hasher)
        {
            var apiKey = apiKeyGenerator.Generate();

            var meansResult = await Publisher.SendRequest <ICreateAuthenticationMeans, IIdentifierResult>(
                new CreateAuthenticationMeans(
                    Guid.NewGuid(), dto.Label, MeansMethod.ApiKey, hasher.Hash(apiKey), DateTimeOffset.UtcNow, null
                    ));

            if (!meansResult.Successful || !meansResult.Id.HasValue)
            {
                throw meansResult.ToException();
            }

            await Publisher.SendRequest <ICreateAssignmentToUser, IIdentifierResult>(
                new CreateAssignmentToUser(Guid.NewGuid(), meansResult.Id.Value, DateTimeOffset.UtcNow, null, id, false)
                );

            return(new CreatedApiKey(meansResult.Id.Value, apiKey));
        }
        public async Task <ActionResult <CreatedApiKey> > CreateApiKey(Guid id, ApiKeyDto dto, [FromServices] IApiKeyGenerator apiKeyGenerator, [FromServices] IMeansValueHasher hasher)
        {
            await _authLoader.AssertResourceAccessAsync(User, id, IsOwnerPolicy.Instance);

            var apiKey = apiKeyGenerator.Generate();

            var meansResult = await Publisher.SendRequest <ICreateAuthenticationMeans, IIdentifierResult>(
                new CreateAuthenticationMeans(
                    Guid.NewGuid(), dto.Label, MeansMethod.ApiKey, hasher.Hash(apiKey), DateTimeOffset.UtcNow, null
                    ));

            if (!meansResult.Successful || !meansResult.Id.HasValue)
            {
                throw meansResult.ToException();
            }

            await Publisher.SendRequest <ICreateAssignmentToPointOfSale, IIdentifierResult>(
                new CreateAssignmentToPointOfSale(Guid.NewGuid(), meansResult.Id.Value, DateTimeOffset.UtcNow, null, id)
                );

            return(new CreatedApiKey(meansResult.Id.Value, apiKey));
        }
Exemple #9
0
 public async Task AddAsync(ApiKeyDto apiKey)
 => await _database.ApiKeys().InsertOneAsync(apiKey);
Exemple #10
0
 public static List <ApiKeyDto> FindAll() => ApiKeyDto.FromEntityList(db.ApiKeys.ToList());