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
2 changes: 1 addition & 1 deletion SecurityService.Client/SecurityServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public async Task<Result> CreateRole(CreateRoleRequest createRoleRequest,
catch(Exception ex)
{
// An exception has occurred, add some additional information to the message
Exception exception = new Exception($"Error creating role {createRoleRequest.Name}.", ex);
Exception exception = new Exception($"Error creating role {createRoleRequest.RoleName}.", ex);

throw exception;
}
Expand Down
79 changes: 1 addition & 78 deletions SecurityService.DataTransferObjects/Requests.cs
Original file line number Diff line number Diff line change
@@ -1,170 +1,93 @@
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace SecurityService.DataTransferObjects;

public sealed class CreateClientRequest
{
[JsonProperty("client_id")]
[JsonPropertyName("client_id")]
public string ClientId { get; set; } = string.Empty;

[JsonPropertyName("secret")]
public string? Secret { get; set; }

[JsonProperty("client_name")]
[JsonPropertyName("client_name")]
public string ClientName { get; set; } = string.Empty;

[JsonProperty("client_description")]
[JsonPropertyName("client_description")]
public string? ClientDescription { get; set; }

[JsonProperty("allowed_scopes")]
[JsonPropertyName("allowed_scopes")]
public List<string> AllowedScopes { get; set; } = new();

[JsonProperty("allowed_grant_types")]
[JsonPropertyName("allowed_grant_types")]
public List<string> AllowedGrantTypes { get; set; } = new();

[JsonProperty("client_uri")]
[JsonPropertyName("client_uri")]
public string? ClientUri { get; set; }

[JsonProperty("client_redirect_uris")]
[JsonPropertyName("client_redirect_uris")]
public List<string> ClientRedirectUris { get; set; } = new();

[JsonProperty("client_post_logout_redirect_uris")]
[JsonPropertyName("client_post_logout_redirect_uris")]
public List<string> ClientPostLogoutRedirectUris { get; set; } = new();

[JsonProperty("require_consent")]
[JsonPropertyName("require_consent")]
public bool RequireConsent { get; set; }

[JsonProperty("allow_offline_access")]
[JsonPropertyName("allow_offline_access")]
public bool AllowOfflineAccess { get; set; }
}

public sealed class CreateApiScopeRequest
{
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

[JsonProperty("display_name")]
[JsonPropertyName("display_name")]
public string? DisplayName { get; set; }

[JsonProperty("description")]
[JsonPropertyName("description")]
public string? Description { get; set; }
}

public sealed class CreateApiResourceRequest
{
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

[JsonProperty("display_name")]
[JsonPropertyName("display_name")]
public string? DisplayName { get; set; }

[JsonProperty("description")]
[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonProperty("secret")]
[JsonPropertyName("secret")]
public string? Secret { get; set; }

[JsonProperty("scopes")]
[JsonPropertyName("scopes")]
public List<string> Scopes { get; set; } = new();

[JsonProperty("user_claims")]
[JsonPropertyName("user_claims")]
public List<string> UserClaims { get; set; } = new();
}

public sealed class CreateIdentityResourceRequest
{
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

[JsonProperty("display_name")]
[JsonPropertyName("display_name")]
public string? DisplayName { get; set; }

[JsonProperty("description")]
[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonProperty("required")]
[JsonPropertyName("required")]
public bool Required { get; set; }

[JsonProperty("emphasize")]
[JsonPropertyName("emphasize")]
public bool Emphasize { get; set; }

[JsonProperty("show_in_discovery_document")]
[JsonPropertyName("show_in_discovery_document")]
public bool ShowInDiscoveryDocument { get; set; } = true;

[JsonProperty("claims")]
[JsonPropertyName("claims")]
public List<string> Claims { get; set; } = new();
}

public sealed class CreateRoleRequest
{
[JsonProperty("role_name")]
[JsonPropertyName("role_name")]
public string Name { get; set; } = string.Empty;
public string RoleName { get; set; } = string.Empty;
}

public sealed class CreateUserRequest
{
[JsonProperty("given_name")]
[JsonPropertyName("given_name")]
public string? GivenName { get; set; }

[JsonProperty("middle_name")]
[JsonPropertyName("middle_name")]
public string? MiddleName { get; set; }

[JsonProperty("family_name")]
[JsonPropertyName("family_name")]
public string? FamilyName { get; set; }

[JsonProperty("user_name")]
[JsonPropertyName("user_name")]
public string UserName { get; set; } = string.Empty;

[JsonProperty("password")]
[JsonPropertyName("password")]
public string Password { get; set; } = string.Empty;

[JsonProperty("email_address")]
[JsonPropertyName("email_address")]
public string? EmailAddress { get; set; }

[JsonProperty("phone_number")]
[JsonPropertyName("phone_number")]
public string? PhoneNumber { get; set; }

[JsonProperty("claims")]
[JsonPropertyName("claims")]
public Dictionary<string, string> Claims { get; set; } = new();

[JsonProperty("roles")]
[JsonPropertyName("roles")]
public List<string> Roles { get; set; } = new();
}

109 changes: 4 additions & 105 deletions SecurityService.DataTransferObjects/Responses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,221 +4,120 @@
namespace SecurityService.DataTransferObjects;

public sealed class ApiResourceResponse {
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; }

Check warning on line 7 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("display_name")]
[JsonPropertyName("display_name")]
public string? DisplayName { get; set; }

[JsonProperty("description")]
[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonProperty("scopes")]
[JsonPropertyName("scopes")]
public IReadOnlyCollection<string> Scopes { get; set; }

Check warning on line 13 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'Scopes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'Scopes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("user_claims")]
[JsonPropertyName("user_claims")]
public IReadOnlyCollection<string> UserClaims { get; set; }

Check warning on line 15 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'UserClaims' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 15 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'UserClaims' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public sealed record ApiScopeResponse {
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; }

Check warning on line 19 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("display_name")]
[JsonPropertyName("display_name")]
public string? DisplayName { get; set; }

[JsonProperty("description")]
[JsonPropertyName("description")]
public string? Description { get; set; }
}

public sealed record ClientResponse {
[JsonProperty("client_id")]
[JsonPropertyName("client_id")]
public string ClientId { get; set; }

Check warning on line 27 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'ClientId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 27 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'ClientId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[JsonProperty("client_name")]
[JsonPropertyName("client_name")]

public string ClientName { get; set; }

Check warning on line 29 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'ClientName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 29 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'ClientName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("client_description")]
[JsonPropertyName("client_description")]
public string? Description { get; set; }

[JsonProperty("client_uri")]
[JsonPropertyName("client_uri")]
public string? ClientUri { get; set; }

[JsonProperty("allowed_scopes")]
[JsonPropertyName("allowed_scopes")]
public IReadOnlyCollection<string> AllowedScopes { get; set; }

Check warning on line 35 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'AllowedScopes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 35 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'AllowedScopes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("allowed_grant_types")]
[JsonPropertyName("allowed_grant_types")]
public IReadOnlyCollection<string> AllowedGrantTypes { get; set; }

Check warning on line 37 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'AllowedGrantTypes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 37 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'AllowedGrantTypes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("client_redirect_uris")]
[JsonPropertyName("client_redirect_uris")]
public IReadOnlyCollection<string> RedirectUris { get; set; }
public IReadOnlyCollection<string> ClientRedirectUris { get; set; }

Check warning on line 39 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'ClientRedirectUris' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 39 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'ClientRedirectUris' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("client_post_logout_redirect_uris")]
[JsonPropertyName("client_post_logout_redirect_uris")]
public IReadOnlyCollection<string> PostLogoutRedirectUris { get; set; }
public IReadOnlyCollection<string> ClientPostLogoutRedirectUris { get; set; }

Check warning on line 41 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'ClientPostLogoutRedirectUris' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("require_consent")]
[JsonPropertyName("require_consent")]
public bool RequireConsent { get; set; }

[JsonProperty("allow_offline_access")]
[JsonPropertyName("allow_offline_access")]
public bool AllowOfflineAccess { get; set; }

[JsonProperty("client_type")]
[JsonPropertyName("client_type")]
public string ClientType { get; set; }
}

public sealed record IdentityResourceResponse
{
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; }

Check warning on line 52 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("display_name")]
[JsonPropertyName("display_name")]
public string? DisplayName { get; set; }

[JsonProperty("description")]
[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonProperty("required")]
[JsonPropertyName("required")]
public bool Required { get; set; }

[JsonProperty("emphasize")]
[JsonPropertyName("emphasize")]
public bool Emphasize { get; set; }

[JsonProperty("show_in_discovery_document")]
[JsonPropertyName("show_in_discovery_document")]
public bool ShowInDiscoveryDocument { get; set; }

[JsonProperty("claims")]
[JsonPropertyName("claims")]
public IReadOnlyCollection<string> Claims { get; set; }

Check warning on line 64 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'Claims' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}


public sealed record RoleResponse
{
[JsonProperty("role_id")]
[JsonPropertyName("role_id")]
public String RoleId { get; set; }

Check warning on line 70 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'RoleId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 70 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'RoleId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("role_name")]
[JsonPropertyName("role_name")]
public string Name { get; set; }
public string RoleName { get; set; }
}

public sealed record UserResponse {
[JsonProperty("user_id")]
[JsonPropertyName("user_id")]
public String UserId { get; set; }

Check warning on line 75 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'UserId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 75 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'UserId' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("user_name")]
[JsonPropertyName("user_name")]
public string UserName { get; set; }

Check warning on line 77 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'UserName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 77 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'UserName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("email_address")]
[JsonPropertyName("email_address")]
public string? EmailAddress { get; set; }

[JsonProperty("phone_number")]
[JsonPropertyName("phone_number")]
public string? PhoneNumber { get; set; }

[JsonProperty("given_name")]
[JsonPropertyName("given_name")]
public string? GivenName { get; set; }

[JsonProperty("middle_name")]
[JsonPropertyName("middle_name")]
public string? MiddleName { get; set; }

[JsonProperty("family_name")]
[JsonPropertyName("family_name")]
public string? FamilyName { get; set; }

[JsonProperty("claims")]
[JsonPropertyName("claims")]
public IReadOnlyDictionary<string, string> Claims{ get; set; }

Check warning on line 89 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'Claims' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 89 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'Claims' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("roles")]
[JsonPropertyName("roles")]
public IReadOnlyCollection<string> Roles { get; set; }

Check warning on line 91 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Non-nullable property 'Roles' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 91 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Non-nullable property 'Roles' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("registration_date_time")]
[JsonPropertyName("registration_date_time")]
public DateTime RegistrationDateTime { get; set; }
}

public class TokenResponse
{
/// <summary>
/// The access token
/// </summary>
/// <value>The access token.</value>
public String AccessToken { get; private set; }

/// <summary>
/// Gets the expires.
/// </summary>
/// <value>The expires.</value>
public DateTimeOffset Expires { get; private set; }

/// <summary>
/// The expires
/// </summary>
/// <value>The expires in.</value>
public Int64 ExpiresIn { get; private set; }

/// <summary>
/// Gets the issued.
/// </summary>
/// <value>The issued.</value>
public DateTimeOffset Issued { get; private set; }

/// <summary>
/// The refresh token
/// </summary>
/// <value>The refresh token.</value>
public String RefreshToken { get; private set; }

public static TokenResponse Create(String token)
{
dynamic auth = JsonConvert.DeserializeObject(token);

Check warning on line 105 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Converting null literal or possible null value to non-nullable type.

Check warning on line 105 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Converting null literal or possible null value to non-nullable type.

Int64 expiresIn = auth["expires_in"].Value;

Check warning on line 107 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Dereference of a possibly null reference.

Check warning on line 107 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Dereference of a possibly null reference.
String accessToken = auth["access_token"].Value;

DateTimeOffset issued = DateTimeOffset.Now;
DateTimeOffset expires = DateTimeOffset.Now.AddSeconds(expiresIn);

String refreshToken = null;

Check warning on line 113 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Converting null literal or possible null value to non-nullable type.

Check warning on line 113 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Converting null literal or possible null value to non-nullable type.
//For client credentials, the refresh_token will not be present
if (auth["refresh_token"] != null)
{
refreshToken = auth["refresh_token"].Value;
}

return TokenResponse.Create(accessToken, refreshToken, expiresIn, issued, expires);

Check warning on line 120 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Chrome UI

Possible null reference argument for parameter 'refreshToken' in 'TokenResponse TokenResponse.Create(string accessToken, string refreshToken, long expiresIn, DateTimeOffset issued = default(DateTimeOffset), DateTimeOffset expires = default(DateTimeOffset))'.

Check warning on line 120 in SecurityService.DataTransferObjects/Responses.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test Pull Requests - Edge UI

Possible null reference argument for parameter 'refreshToken' in 'TokenResponse TokenResponse.Create(string accessToken, string refreshToken, long expiresIn, DateTimeOffset issued = default(DateTimeOffset), DateTimeOffset expires = default(DateTimeOffset))'.
}

public static TokenResponse Create(String accessToken,
Expand Down
Loading
Loading