/// <summary> /// Creates the API scope. /// </summary> /// <param name="createApiScopeRequest">The create API scope request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task <CreateApiScopeResponse> CreateApiScope(CreateApiScopeRequest createApiScopeRequest, CancellationToken cancellationToken) { CreateApiScopeResponse createApiScopeResponse = await this.TestingContext.DockerHelper.SecurityServiceClient.CreateApiScope(createApiScopeRequest, cancellationToken).ConfigureAwait(false); return(createApiScopeResponse); }
/// <summary> /// Creates the API scope. /// </summary> /// <param name="createApiScopeRequest">The create API scope request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <CreateApiScopeResponse> CreateApiScope(CreateApiScopeRequest createApiScopeRequest, CancellationToken cancellationToken) { CreateApiScopeResponse response = null; String requestUri = this.BuildRequestUrl("/api/apiscopes"); try { String requestSerialised = JsonConvert.SerializeObject(createApiScopeRequest); StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json"); // Add the access token to the client headers //this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object response = JsonConvert.DeserializeObject <CreateApiScopeResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error creating api scope {createApiScopeRequest.Name}.", ex); throw exception; } return(response); }
public async Task <IActionResult> CreateApiScope([FromBody] CreateApiScopeRequest createApiScopeRequest, CancellationToken cancellationToken) { String apiScopeName = await this.Manager.CreateApiScope(createApiScopeRequest.Name, createApiScopeRequest.DisplayName, createApiScopeRequest.Description, cancellationToken); // return the result return(this.Created($"{ApiScopeController.ControllerRoute}/{apiScopeName}", new CreateApiScopeResponse { ApiScopeName = apiScopeName })); }
public async Task GivenICreateTheFollowingApiScopes(Table table) { foreach (TableRow tableRow in table.Rows) { CreateApiScopeRequest createApiScopeRequest = new CreateApiScopeRequest { Name = SpecflowTableHelper.GetStringRowValue(tableRow, "Name"), Description = SpecflowTableHelper.GetStringRowValue(tableRow, "Description"), DisplayName = SpecflowTableHelper.GetStringRowValue(tableRow, "DisplayName") }; var createApiScopeResponse = await this.CreateApiScope(createApiScopeRequest, CancellationToken.None).ConfigureAwait(false); createApiScopeResponse.ShouldNotBeNull(); createApiScopeResponse.ApiScopeName.ShouldNotBeNullOrEmpty(); } }