private async Task <CreateIdentityResourceResponse> CreateIdentityResource(CreateIdentityResourceRequest createIdentityResourceRequest, CancellationToken cancellationToken) { CreateIdentityResourceResponse createIdentityResourceResponse = await this.TestingContext.DockerHelper.SecurityServiceClient.CreateIdentityResource(createIdentityResourceRequest, cancellationToken).ConfigureAwait(false); return(createIdentityResourceResponse); }
/// <summary> /// Creates the identity resource. /// </summary> /// <param name="createIdentityResourceRequest">The create identity resource request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <CreateIdentityResourceResponse> CreateIdentityResource(CreateIdentityResourceRequest createIdentityResourceRequest, CancellationToken cancellationToken) { CreateIdentityResourceResponse response = null; String requestUri = this.BuildRequestUrl("/api/identityresources"); try { String requestSerialised = JsonConvert.SerializeObject(createIdentityResourceRequest); 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 <CreateIdentityResourceResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error creating identity resource {createIdentityResourceRequest.DisplayName}.", ex); throw exception; } return(response); }
public async Task <IActionResult> CreateIdentityResource([FromBody] CreateIdentityResourceRequest createIdentityResourceRequest, CancellationToken cancellationToken) { String identityResourceName = await this.Manager.CreateIdentityResource(createIdentityResourceRequest.Name, createIdentityResourceRequest.DisplayName, createIdentityResourceRequest.Description, createIdentityResourceRequest.Required, createIdentityResourceRequest.Emphasize, createIdentityResourceRequest.ShowInDiscoveryDocument, createIdentityResourceRequest.Claims, cancellationToken); // return the result return(this.Created($"{IdentityResourceController.ControllerRoute}/{identityResourceName}", new CreateIdentityResourceResponse { IdentityResourceName = identityResourceName })); }
public async Task GivenICreateTheFollowingIdentityResources(Table table) { foreach (TableRow tableRow in table.Rows) { // Get the scopes String userClaims = SpecflowTableHelper.GetStringRowValue(tableRow, "UserClaims"); CreateIdentityResourceRequest createIdentityResourceRequest = new CreateIdentityResourceRequest { Name = SpecflowTableHelper .GetStringRowValue(tableRow, "Name") .Replace("[id]", this.TestingContext.DockerHelper.TestId.ToString("N")), Claims = string.IsNullOrEmpty(userClaims) ? null : userClaims.Split(",").ToList(), Description = SpecflowTableHelper.GetStringRowValue(tableRow, "Description"), DisplayName = SpecflowTableHelper.GetStringRowValue(tableRow, "DisplayName") }; await this.CreateIdentityResource(createIdentityResourceRequest, CancellationToken.None).ConfigureAwait(false); } }
public async Task GivenICreateTheFollowingIdentityResources(Table table) { foreach (TableRow tableRow in table.Rows) { // Get the scopes String userClaims = SpecflowTableHelper.GetStringRowValue(tableRow, "UserClaims"); CreateIdentityResourceRequest createIdentityResourceRequest = new CreateIdentityResourceRequest { Name = SpecflowTableHelper.GetStringRowValue(tableRow, "Name"), Claims = string.IsNullOrEmpty(userClaims) ? null : userClaims.Split(",").ToList(), Description = SpecflowTableHelper.GetStringRowValue(tableRow, "Description"), DisplayName = SpecflowTableHelper.GetStringRowValue(tableRow, "DisplayName") }; CreateIdentityResourceResponse createIdentityResourceResponse = await this.CreateIdentityResource(createIdentityResourceRequest, CancellationToken.None).ConfigureAwait(false); createIdentityResourceResponse.ShouldNotBeNull(); createIdentityResourceResponse.IdentityResourceName.ShouldNotBeNullOrEmpty(); this.TestingContext.ApiResources.Add(createIdentityResourceResponse.IdentityResourceName); } }
private async Task CreateIdentityResource(CreateIdentityResourceRequest createIdentityResourceRequest, CancellationToken cancellationToken) { CreateIdentityResourceResponse createIdentityResourceResponse = null; List <IdentityResourceDetails> identityResourceList = await this.TestingContext.DockerHelper.SecurityServiceClient.GetIdentityResources(cancellationToken); if (identityResourceList == null || identityResourceList.Any() == false) { createIdentityResourceResponse = await this .TestingContext.DockerHelper.SecurityServiceClient .CreateIdentityResource(createIdentityResourceRequest, cancellationToken) .ConfigureAwait(false); createIdentityResourceResponse.ShouldNotBeNull(); createIdentityResourceResponse.IdentityResourceName.ShouldNotBeNullOrEmpty(); this.TestingContext.IdentityResources.Add(createIdentityResourceResponse.IdentityResourceName); } else { if (identityResourceList.Where(i => i.Name == createIdentityResourceRequest.Name).Any()) { return; } createIdentityResourceResponse = await this .TestingContext.DockerHelper.SecurityServiceClient .CreateIdentityResource(createIdentityResourceRequest, cancellationToken) .ConfigureAwait(false); createIdentityResourceResponse.ShouldNotBeNull(); createIdentityResourceResponse.IdentityResourceName.ShouldNotBeNullOrEmpty(); this.TestingContext.IdentityResources.Add(createIdentityResourceResponse.IdentityResourceName); } }