Refactor auth type to enum in RecActionDto and handler
Changed EndpointAuthType from string to enum in RecActionDto. Updated InvokeRecActionCommandHandler to use enum values in switch statements for improved type safety and maintainability.
This commit is contained in:
@@ -21,7 +21,7 @@ public record RecActionDto
|
|||||||
|
|
||||||
public long? EndpointAuthId { get; init; }
|
public long? EndpointAuthId { get; init; }
|
||||||
|
|
||||||
public string? EndpointAuthType { get; init; }
|
public EndpointAuthType? EndpointAuthType { get; init; }
|
||||||
|
|
||||||
public string? EndpointAuthApiKey { get; init; }
|
public string? EndpointAuthApiKey { get; init; }
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,10 @@ public class InvokeRecActionCommandHandler(
|
|||||||
|
|
||||||
switch (action.EndpointAuthType)
|
switch (action.EndpointAuthType)
|
||||||
{
|
{
|
||||||
case "No Auth":
|
case EndpointAuthType.NoAuth:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "API Key":
|
case EndpointAuthType.ApiKey:
|
||||||
if (action.EndpointAuthApiKey is string apiKey && action.EndpointAuthApiValue is string apiValue)
|
if (action.EndpointAuthApiKey is string apiKey && action.EndpointAuthApiValue is string apiValue)
|
||||||
{
|
{
|
||||||
switch (action.EndpointAuthApiKeyAddTo)
|
switch (action.EndpointAuthApiKeyAddTo)
|
||||||
@@ -86,14 +86,14 @@ public class InvokeRecActionCommandHandler(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Bearer Token":
|
case EndpointAuthType.BearerToken:
|
||||||
case "JWT Bearer":
|
case EndpointAuthType.JwtBearer:
|
||||||
case "OAuth 2.0": // OAuth 2.0 uses Bearer tokens for authenticated requests
|
case EndpointAuthType.OAuth2:
|
||||||
if (action.EndpointAuthToken is string authToken)
|
if (action.EndpointAuthToken is string authToken)
|
||||||
httpReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
httpReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Basic Auth":
|
case EndpointAuthType.BasicAuth:
|
||||||
if (action.EndpointAuthUsername is string authUsername && action.EndpointAuthPassword is string authPassword)
|
if (action.EndpointAuthUsername is string authUsername && action.EndpointAuthPassword is string authPassword)
|
||||||
{
|
{
|
||||||
var basicAuth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{authUsername}:{authPassword}"));
|
var basicAuth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{authUsername}:{authPassword}"));
|
||||||
@@ -101,7 +101,7 @@ public class InvokeRecActionCommandHandler(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "NTLM Auth":
|
case EndpointAuthType.NtlmAuth:
|
||||||
if (!string.IsNullOrWhiteSpace(action.EndpointAuthUsername))
|
if (!string.IsNullOrWhiteSpace(action.EndpointAuthUsername))
|
||||||
{
|
{
|
||||||
var credentials = new NetworkCredential(
|
var credentials = new NetworkCredential(
|
||||||
@@ -113,9 +113,9 @@ public class InvokeRecActionCommandHandler(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Digest Auth":
|
case EndpointAuthType.DigestAuth:
|
||||||
case "OAuth 1.0":
|
case EndpointAuthType.OAuth1:
|
||||||
case "AWS Signature":
|
case EndpointAuthType.AwsSignature:
|
||||||
// These authentication methods require more complex implementations,
|
// These authentication methods require more complex implementations,
|
||||||
// often involving multi-step handshakes or specialized libraries.
|
// often involving multi-step handshakes or specialized libraries.
|
||||||
// They are left as placeholders for future implementation.
|
// They are left as placeholders for future implementation.
|
||||||
|
|||||||
Reference in New Issue
Block a user