Skip to content

Commit

Permalink
Improved code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
engineering87 committed Oct 31, 2024
1 parent 1ab2301 commit 3d4b0d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,38 @@

namespace PDNDClientAssertionGenerator.Services
{
// This service handles the generation of client assertions and the retrieval of access tokens.
/// <summary>
/// This service handles the generation of client assertions and the retrieval of access tokens.
/// </summary>
public class ClientAssertionGeneratorService : IClientAssertionGenerator
{
// Dependency on the OAuth2 service for generating client assertions and requesting tokens.
private readonly IOAuth2Service _oauth2Service;

// Constructor that injects the IOAuth2Service dependency.
// Throws an ArgumentNullException if the provided OAuth2 service is null.
/// <summary>
/// Initializes a new instance of the <see cref="ClientAssertionGeneratorService"/> class.
/// </summary>
/// <param name="oauth2Service">An instance of <see cref="IOAuth2Service"/> used for generating client assertions and requesting tokens.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="oauth2Service"/> is null.</exception>
public ClientAssertionGeneratorService(IOAuth2Service oauth2Service)
{
_oauth2Service = oauth2Service ?? throw new ArgumentNullException(nameof(oauth2Service));
}

// Asynchronously generates a client assertion (JWT) by delegating to the OAuth2 service.
/// <summary>
/// Asynchronously generates a client assertion (JWT) by delegating to the OAuth2 service.
/// </summary>
/// <returns>A task that represents the asynchronous operation, containing the generated client assertion as a string.</returns>
public async Task<string> GetClientAssertionAsync()
{
return await _oauth2Service.GenerateClientAssertionAsync();
}

// Asynchronously requests an OAuth2 access token using the provided client assertion.
// Delegates the actual token request to the OAuth2 service.
/// <summary>
/// Asynchronously requests an OAuth2 access token using the provided client assertion.
/// </summary>
/// <param name="clientAssertion">The client assertion (JWT) used for the token request.</param>
/// <returns>A task that represents the asynchronous operation, containing the response with the access token as a <see cref="PDNDTokenResponse"/>.</returns>
public async Task<PDNDTokenResponse> GetTokenAsync(string clientAssertion)
{
return await _oauth2Service.RequestAccessTokenAsync(clientAssertion);
Expand Down
20 changes: 17 additions & 3 deletions src/PDNDClientAssertionGenerator/Services/OAuth2Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@

namespace PDNDClientAssertionGenerator.Services
{
/// <summary>
/// Service for handling OAuth2 client assertion generation and token requests.
/// </summary>
public class OAuth2Service : IOAuth2Service
{
private readonly ClientAssertionConfig _config;

// Constructor for OAuth2Service, takes a configuration object.
/// <summary>
/// Initializes a new instance of the <see cref="OAuth2Service"/> class.
/// </summary>
/// <param name="config">An <see cref="IOptions{ClientAssertionConfig}"/> object containing the configuration for client assertion generation.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="config"/> is null.</exception>
public OAuth2Service(IOptions<ClientAssertionConfig> config)
{
_config = config.Value ?? throw new ArgumentNullException(nameof(config));
}

// Asynchronously generates a client assertion JWT token.
/// <summary>
/// Asynchronously generates a client assertion (JWT) token.
/// </summary>
/// <returns>A task that represents the asynchronous operation, containing the generated client assertion as a string.</returns>
public async Task<string> GenerateClientAssertionAsync()
{
// Generate a unique token ID (JWT ID)
Expand Down Expand Up @@ -83,7 +93,11 @@ public async Task<string> GenerateClientAssertionAsync()
return await Task.FromResult(clientAssertion); // Return the generated token as a string.
}

// Asynchronously requests an access token by sending the client assertion to the OAuth2 server.
/// <summary>
/// Asynchronously requests an access token by sending the client assertion to the OAuth2 server.
/// </summary>
/// <param name="clientAssertion">The client assertion (JWT) used for the token request.</param>
/// <returns>A task that represents the asynchronous operation, containing the response with the access token as a <see cref="PDNDTokenResponse"/>.</returns>
public async Task<PDNDTokenResponse> RequestAccessTokenAsync(string clientAssertion)
{
using var httpClient = new HttpClient();
Expand Down

0 comments on commit 3d4b0d1

Please sign in to comment.