Skip to content

Commit 0d07800

Browse files
authored
Merge pull request #457 from nofrixion/feature/MOOV-3906-authentication-methods
Feature/moov 3906 authentication methods
2 parents 85c79be + 40a9ac2 commit 0d07800

File tree

6 files changed

+85
-1
lines changed

6 files changed

+85
-1
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,

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/Models/Beneficiary/Beneficiary.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using JetBrains.Annotations;
1919
using System.Text.Json.Serialization;
2020
using Newtonsoft.Json;
21+
using NoFrixion.MoneyMoov.Enums;
2122

2223
#nullable disable
2324

@@ -86,7 +87,12 @@ public class Beneficiary : IValidatableObject
8687
/// The number of distinct authorisers that have authorised the beneficiary.
8788
/// </summary>
8889
public int AuthorisersCompletedCount { get; set; }
89-
90+
91+
/// <summary>
92+
/// A list of authentication types allowed to authorise the payout.
93+
/// </summary>
94+
[CanBeNull] public List<AuthenticationTypesEnum> AuthenticationMethods { get; set; }
95+
9096
public string CreatedByEmailAddress { get; set; }
9197

9298
public string Nonce { get; set; }

src/NoFrixion.MoneyMoov/Models/Payouts/Payout.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// MIT.
1414
// -----------------------------------------------------------------------------
1515

16+
using NoFrixion.MoneyMoov.Enums;
1617
using System.ComponentModel.DataAnnotations;
1718

1819
namespace NoFrixion.MoneyMoov.Models;
@@ -345,6 +346,11 @@ public Counterparty? DestinationAccount
345346
/// </summary>
346347
public List<string>? AuthorisedBy { get; set; }
347348

349+
/// <summary>
350+
/// A list of authentication types allowed to authorise the payout.
351+
/// </summary>
352+
public List<AuthenticationTypesEnum>? AuthenticationMethods { get; set; }
353+
348354
/// <summary>
349355
/// If the payout destination is a beneficiary this will be the ID of it's identifier.
350356
/// </summary>

src/NoFrixion.MoneyMoov/Models/Rules/Rule.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//-----------------------------------------------------------------------------
1515

1616
using System.ComponentModel.DataAnnotations;
17+
using NoFrixion.MoneyMoov.Enums;
1718
using Quartz;
1819
using static System.String;
1920

@@ -119,6 +120,11 @@ public class Rule : IValidatableObject, IWebhookPayload
119120

120121
public required string Nonce { get; set; }
121122

123+
/// <summary>
124+
/// A list of authentication types allowed to authorise the payout.
125+
/// </summary>
126+
public List<AuthenticationTypesEnum>? AuthenticationMethods { get; set; }
127+
122128
/// <summary>
123129
/// The approval hash is used when approving the rule and to detect when critical
124130
/// fields change.

0 commit comments

Comments
 (0)