Skip to content

Commit 8943cdc

Browse files
authored
Added additional identity claim checks for merhcant tokens. (#470)
1 parent 4a40d45 commit 8943cdc

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/NoFrixion.MoneyMoov/Claims/IdentityExtensions.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,36 @@ public static bool IsVerfiedByApiKey(this IIdentity identity)
6262
return bool.TryParse(verifiedClaim, out var verifiedByApiKey) && verifiedByApiKey;
6363
}
6464

65-
public static bool IsVerfiedMerchantToken(this IIdentity identity)
65+
/// <summary>
66+
/// Returns true if the request was authenticated with a merchant JWT bearer token.
67+
/// </summary>
68+
public static bool IsMerchantTokenBearer(this IIdentity identity)
6669
{
67-
var verifiedClaim = ((ClaimsIdentity)identity)?.FindFirst(x => x.Type == ClaimsConstants.NOFRIXION_CLAIMS_NAMESPACE + NoFrixionClaimsEnum.verified_merchant_token)?.Value;
70+
var verifiedClaim = ((ClaimsIdentity)identity)?.FindFirst(x => x.Type == ClaimsConstants.NOFRIXION_CLAIMS_NAMESPACE + NoFrixionClaimsEnum.merchant_token_bearer)?.Value;
6871

6972
return bool.TryParse(verifiedClaim, out var verifiedMerchantToken) && verifiedMerchantToken;
7073
}
7174

75+
/// <summary>
76+
/// Returns true if a merchant token authenticated request was from a whitelisted source IP address.
77+
/// </summary>
78+
public static bool IsMerchantTokenIPAddressWhiteLised(this IIdentity identity)
79+
{
80+
var ipAddressWhitelistClaim = ((ClaimsIdentity)identity)?.FindFirst(x => x.Type == ClaimsConstants.NOFRIXION_CLAIMS_NAMESPACE + NoFrixionClaimsEnum.merchant_token_whitelisted_ipaddress)?.Value;
81+
82+
return bool.TryParse(ipAddressWhitelistClaim, out var isRquestIPAddressWhiteListed) && isRquestIPAddressWhiteListed;
83+
}
84+
85+
/// <summary>
86+
/// Returns true if a merchant token authenticated request was authenticated with an HMAC or public key signature.
87+
/// </summary>
88+
public static bool IsMerchantTokenSigned(this IIdentity identity)
89+
{
90+
var isSignedClaim = ((ClaimsIdentity)identity)?.FindFirst(x => x.Type == ClaimsConstants.NOFRIXION_CLAIMS_NAMESPACE + NoFrixionClaimsEnum.merchant_token_signed)?.Value;
91+
92+
return bool.TryParse(isSignedClaim, out var isSigned) && isSigned;
93+
}
94+
7295
public static bool MerchantIdExists(this IIdentity identity)
7396
{
7497
return identity != null && ((ClaimsIdentity)identity).Claims.Any(x => x.Type == ClaimsConstants.NOFRIXION_CLAIMS_NAMESPACE + NoFrixionClaimsEnum.merchantid);

src/NoFrixion.MoneyMoov/Claims/NoFrixionClaimsEnum.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,17 @@ public enum NoFrixionClaimsEnum
101101
use_permissions,
102102

103103
/// <summary>
104-
/// The token was successfully authenticated by the merchant token middleware.
104+
/// If set indicates the request was authenticated with a JWT bearer token.
105105
/// </summary>
106-
verified_merchant_token
106+
merchant_token_bearer,
107+
108+
/// <summary>
109+
/// If set indicates the request was was received from a source address on the merchant token's IP address whitelist.
110+
/// </summary>
111+
merchant_token_whitelisted_ipaddress,
112+
113+
/// <summary>
114+
/// If set indicates the request was authenticated by a signed (HMAC or public key) merchant token.
115+
/// </summary>
116+
merchant_token_signed
107117
}

0 commit comments

Comments
 (0)