Skip to content

Commit

Permalink
Merge branch 'release/comp-1.8.38'
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsorcery committed Nov 22, 2024
2 parents 8ae6cc9 + 170fbfa commit 1620ad5
Show file tree
Hide file tree
Showing 25 changed files with 618 additions and 151 deletions.
31 changes: 31 additions & 0 deletions src/NoFrixion.MoneyMoov/Claims/IdentityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Security.Claims;
using System.Security.Principal;
using NoFrixion.Common.Permissions;
using NoFrixion.MoneyMoov.Enums;
using NoFrixion.MoneyMoov.Extensions;
using NoFrixion.MoneyMoov.Models;

Expand Down Expand Up @@ -339,6 +340,36 @@ public static bool HasMerchantPermission(this IIdentity identity, MerchantPermis

return Enum.TryParse(claim.Value, out MerchantPermissions claimPermissions) && claimPermissions.HasFlag(permission);
}

/// <summary>
/// Gets the authentication type from the identity token.
/// </summary>
/// <param name="identity">The token identity</param>
/// <returns>The authentication type.</returns>
public static AuthenticationTypesEnum GetAuthenticationType(this IIdentity identity)
{
var claimsIdentity = identity as ClaimsIdentity;

if (claimsIdentity == null)
{
return AuthenticationTypesEnum.None;
}
else
{
var authenticationClaimType = ClaimsConstants.NOFRIXION_CLAIMS_NAMESPACE + NoFrixionClaimsEnum.approveamr;

var authenticationTypeClaimValue = claimsIdentity.Claims.FirstOrDefault(x => x.Type == authenticationClaimType)?.Value;

if (Enum.TryParse(authenticationTypeClaimValue, out AuthenticationTypesEnum authenticationType))
{
return authenticationType;
}
else
{
return AuthenticationTypesEnum.None;
}
}
}
}

#nullable enable
1 change: 1 addition & 0 deletions src/NoFrixion.MoneyMoov/Enums/AuthenticationTypesEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace NoFrixion.MoneyMoov.Enums;

[Flags]
public enum AuthenticationTypesEnum
{
None = 0,
Expand Down
35 changes: 35 additions & 0 deletions src/NoFrixion.MoneyMoov/Enums/SharedSecretAlgorithmsEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//-----------------------------------------------------------------------------
// Filename: SharedSecretAlgorithmsEnum.cs
//
// Description: A list of the shared secret algorithms supported. Original use
// case was for adding an HMAC option to the merchant tokens.
//
// Author(s):
// Aaron Clauson ([email protected])
//
// History:
// Halloween 2024 Aaron Clauson Created, Carne, Wexford, Ireland.
//
// License:
// Proprietary NoFrixion.
//-----------------------------------------------------------------------------

namespace NoFrixion.MoneyMoov;

public enum SharedSecretAlgorithmsEnum
{
None,

/// <summary>
/// Only supported for legacy reasons. NOT supported for merchant or api token HMACs
/// </summary>
HMAC_SHA1,

HMAC_SHA256,
HMAC_SHA384,

/// <summary>
/// Recommended.
/// </summary>
HMAC_SHA512
}
34 changes: 34 additions & 0 deletions src/NoFrixion.MoneyMoov/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,40 @@ public static List<T> ToList<T>(this T flags) where T : Enum
}
}

/// <summary>
/// This method converts an Enum with the Flags attribute to a list of Enums.
/// </summary>
public static List<T> ToList<T>(this T? flags) where T : struct, Enum
{
if (!typeof(T).IsDefined(typeof(FlagsAttribute), false))
{
throw new ArgumentException("The type parameter T must have the Flags attribute.", nameof(flags));
}

if (flags == null)
{
return [];
}

// Check if the enum underlying type is ulong
var underlyingType = Enum.GetUnderlyingType(typeof(T));

if (underlyingType == typeof(ulong))
{
return Enum.GetValues(typeof(T))
.Cast<T>()
.Where(value => flags.Value.HasFlag(value) && Convert.ToUInt64(value) != 0) // Exclude None or 0
.ToList();
}
else
{
return Enum.GetValues(typeof(T))
.Cast<T>()
.Where(value => flags.Value.HasFlag(value) && Convert.ToInt32(value) != 0) // Exclude None or 0
.ToList();
}
}

/// <summary>
/// This method converts list of flag enum values to a single flag enum.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public static class HmacAuthenticationConstants
public const string MERCHANT_ID_HEADER_NAME = "x-nfx-merchantid";
public const string NOFRIXION_SIGNATURE_HEADER_NAME = "x-nfx-signature";
public const string HTTP_RETRY_HEADER_NAME = "x-mod-retry";
public const string IDEMPOTENT_HEADER_NAME = "idempotency-key";
public const string IDEMPOTENT_HEADER_NAME = "idempotency-key";
public const string TOKEN_ID_PARAMETER_NAME = "tokenId";
}
106 changes: 0 additions & 106 deletions src/NoFrixion.MoneyMoov/HmacSignature/HmacSignatureAuthHelper.cs

This file was deleted.

Loading

0 comments on commit 1620ad5

Please sign in to comment.