Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions SecurityService.Client/ISecurityServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public interface ISecurityServiceClient
Task<CreateApiResourceResponse> CreateApiResource(CreateApiResourceRequest createApiResourceRequest,
CancellationToken cancellationToken);

/// <summary>
/// Creates the API scope.
/// </summary>
/// <param name="createApiScopeRequest">The create API scope request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<CreateApiScopeResponse> CreateApiScope(CreateApiScopeRequest createApiScopeRequest,
CancellationToken cancellationToken);

/// <summary>
/// Creates the client.
/// </summary>
Expand Down Expand Up @@ -69,13 +78,29 @@ Task<CreateUserResponse> CreateUser(CreateUserRequest createUserRequest,
Task<ApiResourceDetails> GetApiResource(String apiResourceName,
CancellationToken cancellationToken);

/// <summary>
/// Gets the API scope.
/// </summary>
/// <param name="apiScopeName">Name of the API scope.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<ApiScopeDetails> GetApiScope(String apiScopeName,
CancellationToken cancellationToken);

/// <summary>
/// Gets the API resources.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<List<ApiResourceDetails>> GetApiResources(CancellationToken cancellationToken);

/// <summary>
/// Gets the API scopes.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<List<ApiScopeDetails>> GetApiScopes(CancellationToken cancellationToken);

/// <summary>
/// Gets the client.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions SecurityService.Client/SecurityService.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClientProxyBase" Version="0.0.8.1" />
<PackageReference Include="ClientProxyBase" Version="1.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
113 changes: 113 additions & 0 deletions SecurityService.Client/SecurityServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,47 @@ public async Task<CreateApiResourceResponse> CreateApiResource(CreateApiResource
return response;
}

/// <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;
}

/// <summary>
/// Creates the client.
/// </summary>
Expand Down Expand Up @@ -331,6 +372,78 @@ public async Task<List<ApiResourceDetails>> GetApiResources(CancellationToken ca
return response;
}

/// <summary>
/// Gets the API scope.
/// </summary>
/// <param name="apiScopeName">Name of the API scope.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
public async Task<ApiScopeDetails> GetApiScope(String apiScopeName,
CancellationToken cancellationToken)
{
ApiScopeDetails response = null;
String requestUri = this.BuildRequestUrl($"/api/apiscopes/{apiScopeName}");

try
{
// 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.GetAsync(requestUri, 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<ApiScopeDetails>(content);
}
catch(Exception ex)
{
// An exception has occurred, add some additional information to the message
Exception exception = new Exception($"Error getting api scope {apiScopeName}.", ex);

throw exception;
}

return response;
}

/// <summary>
/// Gets the API scopes.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
public async Task<List<ApiScopeDetails>> GetApiScopes(CancellationToken cancellationToken)
{
List<ApiScopeDetails> response = null;
String requestUri = this.BuildRequestUrl("/api/apiscopes");

try
{
// 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.GetAsync(requestUri, 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<List<ApiScopeDetails>>(content);
}
catch(Exception ex)
{
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting api scopes.", ex);

throw exception;
}

return response;
}

/// <summary>
/// Gets the client.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace SecurityService.DataTransferObjects.Requests
{
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

[ExcludeFromCodeCoverage]
public class CreateApiScopeRequest
{
#region Properties

/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>
/// The description.
/// </value>
[JsonProperty("description")]
public String Description { get; set; }

/// <summary>
/// Gets or sets the display name.
/// </summary>
/// <value>
/// The display name.
/// </value>
[JsonProperty("display_name")]
public String DisplayName { get; set; }

/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
[JsonProperty("name")]
public String Name { get; set; }

#endregion
}
}
50 changes: 50 additions & 0 deletions SecurityService.DataTransferObjects/Responses/ApiScopeDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace SecurityService.DataTransferObjects.Responses
{
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

[ExcludeFromCodeCoverage]
public class ApiScopeDetails
{
#region Properties

/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>
/// The description.
/// </value>
[JsonProperty("description")]
public String Description { get; set; }

/// <summary>
/// Gets or sets the display name.
/// </summary>
/// <value>
/// The display name.
/// </value>
[JsonProperty("display_name")]
public String DisplayName { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this <see cref="ApiResourceDetails"/> is enabled.
/// </summary>
/// <value>
/// <c>true</c> if enabled; otherwise, <c>false</c>.
/// </value>
[JsonProperty("enabled")]
public Boolean Enabled { get; set; }

/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
[JsonProperty("name")]
public String Name { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace SecurityService.DataTransferObjects.Responses
{
using System;
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

[ExcludeFromCodeCoverage]
public class CreateApiScopeResponse
{
/// <summary>
/// Gets or sets the name of the API scope.
/// </summary>
/// <value>
/// The name of the API scope.
/// </value>
[JsonProperty("api_scope_name")]
public String ApiScopeName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

</Project>
Loading