public async Task <IActionResult> CreateKey(CreateApiKeyRequest request)
        {
            if (request is null)
            {
                return(NotFound());
            }
            if (request.Permissions is null || request.Permissions.Length == 0)
            {
                ModelState.AddModelError(nameof(request.Permissions), "One or more permissions are required");
                return(this.CreateValidationError(ModelState));
            }
            var key = new APIKeyData()
            {
                Id     = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20)),
                Type   = APIKeyType.Permanent,
                UserId = _userManager.GetUserId(User),
                Label  = request.Label
            };

            key.SetBlob(new APIKeyBlob()
            {
                Permissions = request.Permissions.Select(p => p.ToString()).Distinct().ToArray()
            });
            await _apiKeyRepository.CreateKey(key);

            return(Ok(FromModel(key)));
        }
        public void PostWalletsHFTest()
        {
            var walletId = "";

            Step("Make POST /api/wallets/hft and validate response", () =>
            {
                var model = new CreateApiKeyRequest
                {
                    Description = "Autotest HFT description",
                    Name        = "Autotest HFT description, delete me"
                };

                var response = apiV2.wallets.PostWalletHFT(model, token);

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

                Assert.That(response.GetResponseObject().WalletId, Is.Not.Null.Or.Empty);
                Assert.That(response.GetResponseObject().ApiKey, Is.Not.Null.Or.Empty);
                walletId = response.GetResponseObject().WalletId;
            });

            if (walletId != "")
            {
                Step($"Make DELETE /api/wallets/{walletId} and remove wallet", () =>
                {
                    var response = apiV2.wallets.DeleteWallet(walletId, token);
                });
            }
        }
Example #3
0
        /// <summary>
        /// Create an API key for a specific user Requires the User Admin Role.
        /// </summary>
        /// <exception cref="mantle.lib.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request"> (optional)</param>
        /// <returns>Task of ApiResponse</returns>
        public async System.Threading.Tasks.Task <ApiResponse <Object> > ApiKeysPostAsyncWithHttpInfo(CreateApiKeyRequest request = null)
        {
            var    localVarPath         = "./apikeys";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
            };
            String localVarHttpHeaderAccept    = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (request != null && request.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(request); // http body (model) parameter
            }
            else
            {
                localVarPostBody = request; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("ApiKeysPost", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Object>(localVarStatusCode,
                                            localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
                                            null));
        }
        public async Task CreateAsync(CreateApiKeyRequest request)
        {
            var entity = new ApiKeyEntity
            {
                Owner       = request.Owner,
                Permissions = request.Permissions
            };

            await(await _container).CreateItemAsync(await _entityMutator.CreateMetadataAsync(entity, request.SharedWith));
        }
        public virtual async Task <ApiKeyData> CreateAPIKey(CreateApiKeyRequest request, CancellationToken token = default)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/api-keys", bodyPayload : request, method : HttpMethod.Post), token);

            return(await HandleResponse <ApiKeyData>(response));
        }
        public void PostWalletsHFTEmptyObjectTest()
        {
            Step("Make POST /api/wallets/hft and validate response", () =>
            {
                var model = new CreateApiKeyRequest
                {
                };

                var response = apiV2.wallets.PostWalletHFT(model, token);

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            });
        }
        public async Task <IActionResult> CreateApiWallet([FromBody] CreateApiKeyRequest request)
        {
            var apiKey = await _hftInternalService.CreateKeyAsync(
                new Lykke.Service.HftInternalService.Client.AutorestClient.Models.CreateApiKeyRequest(_requestContext.ClientId, request.Name, request.Description));

            if (apiKey == null)
            {
                return(BadRequest());
            }

            return(Ok(new CreateApiKeyResponse {
                ApiKey = apiKey.Key, WalletId = apiKey.Wallet
            }));
        }
        public void PostWalletsHFTInvalidTokenTest()
        {
            Step("Make POST /api/wallets/hft and validate response", () =>
            {
                var model = new CreateApiKeyRequest
                {
                    Description = "Autotest HFT description",
                    Name        = "Autotest HFT description, delete me"
                };

                var response = apiV2.wallets.PostWalletHFT(model, Guid.NewGuid().ToString());

                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            });
        }
Example #9
0
        /**
         * Create Key from CreateApiKeyRequest
         */
        public async Task <string> CreateKey(CreateApiKeyRequest createApiKeyRequest, string ipAddress)
        {
            var createApiResponse       = new CreateApiResponse();
            var createApiFailedResponse = new CreateApiResponseFailed();

            var account = await this._accountRepository.GetAccountByLogin(createApiKeyRequest.login);

            //return failed if account is wrong
            if (account == null || account.Password != createApiKeyRequest.password)
            {
                createApiFailedResponse.Reason = Enum.GetName(typeof(CreateApiFailedEnum), CreateApiFailedEnum.FAILED);
                return(JsonConvert.SerializeObject(createApiFailedResponse));
            }

            this._accountRepository.Entities().AddOrUpdate(account.Id, account, (i, editedAccount) =>
            {
                //if expired token or empty
                if (account.ApiKeyExpirationDate == null || (DateTime)account.ApiKeyExpirationDate <= DateTime.Now)
                {
                    editedAccount.ApiKey = Guid.NewGuid().ToString();
                    editedAccount.ApiKeyExpirationDate = DateTime.Now.AddHours(50);//4
                }

                editedAccount.Ip       = ipAddress;
                editedAccount.IsEdited = true;

                return(editedAccount);
            });


            createApiResponse.AccountId = account.Id;
            createApiResponse.AddedDate = DateTimeOffset.Now;
            createApiResponse.Data      = new CreateApiResponseData()
            {
                Country  = "FR",
                Currency = "EUR"
            };
            createApiResponse.Key            = account.ApiKey;
            createApiResponse.ExpirationDate = DateTime.Now.AddHours(50);//4
            createApiResponse.RefreshToken   = "";
            createApiResponse.Ip             = account.Ip;

            return(JsonConvert.SerializeObject(createApiResponse));
        }
        public async Task <IActionResult> CreateApiWallet([FromBody] CreateApiKeyRequest request)
        {
            var apiKey = await _hftInternalService.Keys.CreateKey(new CreateApiKeyModel
            {
                ClientId    = _requestContext.ClientId,
                Name        = request.Name,
                Description = request.Description,
                Apiv2Only   = request.Apiv2Only
            });

            if (apiKey == null)
            {
                return(BadRequest());
            }

            return(Ok(new CreateApiKeyResponse {
                ApiKey = apiKey.ApiKey, WalletId = apiKey.WalletId, Name = request.Name, Description = request.Description, Apiv2Only = request.Apiv2Only
            }));
        }
        public async Task <IActionResult> CreateKey([FromBody] CreateApiKeyRequest request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            var client = await _clientAccountService.GetClientByIdAsync(request.ClientId);

            if (client == null)
            {
                ModelState.AddModelError("ClientId", request.ClientId);
                return(BadRequest(ModelState));
            }

            var apiKey = await _walletService.CreateWallet(request.ClientId, request.Apiv2Only, request.Name, request.Description);

            return(Ok(_mapper.Map <ApiKeyDto>(apiKey)));
        }
        public async Task <ActionResult <ApiKeyData> > CreateKey(CreateApiKeyRequest request)
        {
            if (request is null)
            {
                return(BadRequest());
            }
            var key = new APIKeyData()
            {
                Id     = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20)),
                Type   = APIKeyType.Permanent,
                UserId = _userManager.GetUserId(User),
                Label  = request.Label
            };

            key.Permissions = string.Join(";", request.Permissions.Select(p => p.ToString()).Distinct().ToArray());
            await _apiKeyRepository.CreateKey(key);

            return(Ok(FromModel(key)));
        }
Example #13
0
        public async Task <IActionResult> CreateKey(CreateApiKeyRequest request)
        {
            request ??= new CreateApiKeyRequest();
            request.Permissions ??= System.Array.Empty <Permission>();
            var key = new APIKeyData()
            {
                Id     = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20)),
                Type   = APIKeyType.Permanent,
                UserId = _userManager.GetUserId(User),
                Label  = request.Label
            };

            key.SetBlob(new APIKeyBlob()
            {
                Permissions = request.Permissions.Select(p => p.ToString()).Distinct().ToArray()
            });
            await _apiKeyRepository.CreateKey(key);

            return(Ok(FromModel(key)));
        }
 public IResponse <CreateApiKeyResponse> PostWalletHFT(CreateApiKeyRequest request, string authorization) =>
 Request.Post("/wallets/hft").AddJsonBody(request).WithBearerToken(authorization).Build().Execute <CreateApiKeyResponse>();
Example #15
0
 /// <summary>
 /// Create an API key for a specific user Requires the User Admin Role.
 /// </summary>
 /// <exception cref="mantle.lib.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="xApiKey"></param>
 /// <param name="request"> (optional)</param>
 /// <returns>Task of void</returns>
 public async System.Threading.Tasks.Task CreateApiKeyAsync(string xApiKey, CreateApiKeyRequest request = null)
 {
     await CreateApiKeyAsyncWithHttpInfo(xApiKey, request);
 }
Example #16
0
        /// <summary>
        /// Create an API key for a specific user Requires the User Admin Role.
        /// </summary>
        /// <exception cref="mantle.lib.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="xApiKey"></param>
        /// <param name="request"> (optional)</param>
        /// <returns>ApiResponse of Object(void)</returns>
        public ApiResponse <Object> CreateApiKeyWithHttpInfo(string xApiKey, CreateApiKeyRequest request = null)
        {
            // verify the required parameter 'xApiKey' is set
            if (xApiKey == null)
            {
                throw new ApiException(400, "Missing required parameter 'xApiKey' when calling ApiKeysApi->CreateApiKey");
            }

            var    localVarPath         = "/apikeys";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
            };
            String localVarHttpHeaderAccept    = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (xApiKey != null)
            {
                localVarHeaderParams.Add("x-api-key", this.Configuration.ApiClient.ParameterToString(xApiKey));                  // header parameter
            }
            if (request != null && request.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(request); // http body (model) parameter
            }
            else
            {
                localVarPostBody = request; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)this.Configuration.ApiClient.CallApi(localVarPath,
                                                                                                 Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                 localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("CreateApiKey", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <Object>(localVarStatusCode,
                                            localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                            null));
        }
Example #17
0
 /// <summary>
 /// Create an API key for a specific user Requires the User Admin Role.
 /// </summary>
 /// <exception cref="mantle.lib.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="xApiKey"></param>
 /// <param name="request"> (optional)</param>
 /// <returns></returns>
 public void CreateApiKey(string xApiKey, CreateApiKeyRequest request = null)
 {
     CreateApiKeyWithHttpInfo(xApiKey, request);
 }
Example #18
0
 /// <summary>
 /// Create an API key for a specific user Requires the User Admin Role.
 /// </summary>
 /// <exception cref="mantle.lib.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="request"> (optional)</param>
 /// <returns>Task of void</returns>
 public async System.Threading.Tasks.Task ApiKeysPostAsync(CreateApiKeyRequest request = null)
 {
     await ApiKeysPostAsyncWithHttpInfo(request);
 }
Example #19
0
 /// <summary>
 /// Create an API key for a specific user Requires the User Admin Role.
 /// </summary>
 /// <exception cref="mantle.lib.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="request"> (optional)</param>
 /// <returns></returns>
 public void ApiKeysPost(CreateApiKeyRequest request = null)
 {
     ApiKeysPostWithHttpInfo(request);
 }
 public async Task CreateAsync(CreateApiKeyRequest request) =>
 await _service.CreateAsync(request);
 public async Task CreateAsync(CreateApiKeyRequest request) =>
 await _writeRepository.CreateAsync(request);