Skip to content

Commit 1620ad5

Browse files
committed
Merge branch 'release/comp-1.8.38'
2 parents 8ae6cc9 + 170fbfa commit 1620ad5

File tree

25 files changed

+618
-151
lines changed

25 files changed

+618
-151
lines changed

src/NoFrixion.MoneyMoov/Claims/IdentityExtensions.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Security.Claims;
2020
using System.Security.Principal;
2121
using NoFrixion.Common.Permissions;
22+
using NoFrixion.MoneyMoov.Enums;
2223
using NoFrixion.MoneyMoov.Extensions;
2324
using NoFrixion.MoneyMoov.Models;
2425

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

340341
return Enum.TryParse(claim.Value, out MerchantPermissions claimPermissions) && claimPermissions.HasFlag(permission);
341342
}
343+
344+
/// <summary>
345+
/// Gets the authentication type from the identity token.
346+
/// </summary>
347+
/// <param name="identity">The token identity</param>
348+
/// <returns>The authentication type.</returns>
349+
public static AuthenticationTypesEnum GetAuthenticationType(this IIdentity identity)
350+
{
351+
var claimsIdentity = identity as ClaimsIdentity;
352+
353+
if (claimsIdentity == null)
354+
{
355+
return AuthenticationTypesEnum.None;
356+
}
357+
else
358+
{
359+
var authenticationClaimType = ClaimsConstants.NOFRIXION_CLAIMS_NAMESPACE + NoFrixionClaimsEnum.approveamr;
360+
361+
var authenticationTypeClaimValue = claimsIdentity.Claims.FirstOrDefault(x => x.Type == authenticationClaimType)?.Value;
362+
363+
if (Enum.TryParse(authenticationTypeClaimValue, out AuthenticationTypesEnum authenticationType))
364+
{
365+
return authenticationType;
366+
}
367+
else
368+
{
369+
return AuthenticationTypesEnum.None;
370+
}
371+
}
372+
}
342373
}
343374

344375
#nullable enable

src/NoFrixion.MoneyMoov/Enums/AuthenticationTypesEnum.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace NoFrixion.MoneyMoov.Enums;
1818

19+
[Flags]
1920
public enum AuthenticationTypesEnum
2021
{
2122
None = 0,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//-----------------------------------------------------------------------------
2+
// Filename: SharedSecretAlgorithmsEnum.cs
3+
//
4+
// Description: A list of the shared secret algorithms supported. Original use
5+
// case was for adding an HMAC option to the merchant tokens.
6+
//
7+
// Author(s):
8+
// Aaron Clauson ([email protected])
9+
//
10+
// History:
11+
// Halloween 2024 Aaron Clauson Created, Carne, Wexford, Ireland.
12+
//
13+
// License:
14+
// Proprietary NoFrixion.
15+
//-----------------------------------------------------------------------------
16+
17+
namespace NoFrixion.MoneyMoov;
18+
19+
public enum SharedSecretAlgorithmsEnum
20+
{
21+
None,
22+
23+
/// <summary>
24+
/// Only supported for legacy reasons. NOT supported for merchant or api token HMACs
25+
/// </summary>
26+
HMAC_SHA1,
27+
28+
HMAC_SHA256,
29+
HMAC_SHA384,
30+
31+
/// <summary>
32+
/// Recommended.
33+
/// </summary>
34+
HMAC_SHA512
35+
}

src/NoFrixion.MoneyMoov/Extensions/EnumExtensions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,40 @@ public static List<T> ToList<T>(this T flags) where T : Enum
4646
}
4747
}
4848

49+
/// <summary>
50+
/// This method converts an Enum with the Flags attribute to a list of Enums.
51+
/// </summary>
52+
public static List<T> ToList<T>(this T? flags) where T : struct, Enum
53+
{
54+
if (!typeof(T).IsDefined(typeof(FlagsAttribute), false))
55+
{
56+
throw new ArgumentException("The type parameter T must have the Flags attribute.", nameof(flags));
57+
}
58+
59+
if (flags == null)
60+
{
61+
return [];
62+
}
63+
64+
// Check if the enum underlying type is ulong
65+
var underlyingType = Enum.GetUnderlyingType(typeof(T));
66+
67+
if (underlyingType == typeof(ulong))
68+
{
69+
return Enum.GetValues(typeof(T))
70+
.Cast<T>()
71+
.Where(value => flags.Value.HasFlag(value) && Convert.ToUInt64(value) != 0) // Exclude None or 0
72+
.ToList();
73+
}
74+
else
75+
{
76+
return Enum.GetValues(typeof(T))
77+
.Cast<T>()
78+
.Where(value => flags.Value.HasFlag(value) && Convert.ToInt32(value) != 0) // Exclude None or 0
79+
.ToList();
80+
}
81+
}
82+
4983
/// <summary>
5084
/// This method converts list of flag enum values to a single flag enum.
5185
/// </summary>

src/NoFrixion.MoneyMoov/HmacSignature/HmacAuthenticationConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public static class HmacAuthenticationConstants
2525
public const string MERCHANT_ID_HEADER_NAME = "x-nfx-merchantid";
2626
public const string NOFRIXION_SIGNATURE_HEADER_NAME = "x-nfx-signature";
2727
public const string HTTP_RETRY_HEADER_NAME = "x-mod-retry";
28-
public const string IDEMPOTENT_HEADER_NAME = "idempotency-key";
28+
public const string IDEMPOTENT_HEADER_NAME = "idempotency-key";
29+
public const string TOKEN_ID_PARAMETER_NAME = "tokenId";
2930
}

src/NoFrixion.MoneyMoov/HmacSignature/HmacSignatureAuthHelper.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)