Skip to content

Commit 84f77ac

Browse files
authored
Merge pull request #1159 from ITfoxtec/test
Test
2 parents c85cf6b + 3b218fc commit 84f77ac

File tree

9 files changed

+52
-24
lines changed

9 files changed

+52
-24
lines changed

src/FoxIDs.Control/FoxIDs.Control.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<Version>1.15.20</Version>
5+
<Version>1.15.21</Version>
66
<RootNamespace>FoxIDs</RootNamespace>
77
<Authors>Anders Revsgaard</Authors>
88
<Company>ITfoxtec</Company>

src/FoxIDs.ControlClient/FoxIDs.ControlClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<Version>1.15.20</Version>
5+
<Version>1.15.21</Version>
66
<RootNamespace>FoxIDs.Client</RootNamespace>
77
<Authors>Anders Revsgaard</Authors>
88
<Company>ITfoxtec</Company>

src/FoxIDs.ControlShared/FoxIDs.ControlShared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<Version>1.15.20</Version>
5+
<Version>1.15.21</Version>
66
<RootNamespace>FoxIDs</RootNamespace>
77
<Authors>Anders Revsgaard</Authors>
88
<Company>ITfoxtec</Company>

src/FoxIDs.Shared/FoxIDs.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<Version>1.15.20</Version>
5+
<Version>1.15.21</Version>
66
<RootNamespace>FoxIDs</RootNamespace>
77
<Authors>Anders Revsgaard</Authors>
88
<Company>ITfoxtec</Company>

src/FoxIDs.SharedBase/Constants.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,11 @@ public static class DynamicElements
571571
public static class Claim
572572
{
573573
public const int JwtTypeLength = 100;
574-
public const string JwtTypeRegExPattern = @"^[\w:\/\-.+]*$";
575-
public const string JwtTypeWildcardRegExPattern = @"^[\w:\/\-.+\*]*$";
574+
public const string JwtTypeRegExPattern = @"^[\w:\/\-.+ ]*$";
575+
public const string JwtTypeWildcardRegExPattern = @"^[\w:\/\-.+ \*]*$";
576576
public const int SamlTypeLength = 300;
577-
public const string SamlTypeRegExPattern = @"^[\w:\/\-.+]*$";
578-
public const string SamlTypeWildcardRegExPattern = @"^[\w:\/\-.+\*]*$";
577+
public const string SamlTypeRegExPattern = @"^[\w:\/\-.+ ]*$";
578+
public const string SamlTypeWildcardRegExPattern = @"^[\w:\/\-.+ \*]*$";
579579

580580
public const int ValuesOAuthMin = 0;
581581
public const int ValuesUserMin = 1;

src/FoxIDs.SharedBase/FoxIDs.SharedBase.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<Version>1.15.20</Version>
5+
<Version>1.15.21</Version>
66
<RootNamespace>FoxIDs</RootNamespace>
77
<Authors>Anders Revsgaard</Authors>
88
<Company>ITfoxtec</Company>

src/FoxIDs/FoxIDs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
33
<TargetFramework>net9.0</TargetFramework>
4-
<Version>1.15.20</Version>
4+
<Version>1.15.21</Version>
55
<RootNamespace>FoxIDs</RootNamespace>
66
<Authors>Anders Revsgaard</Authors>
77
<Company>ITfoxtec</Company>

src/FoxIDs/Logic/OAuth/OAuthAuthCodeGrantDownLogic.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,26 @@ public async Task<string> CreateAuthCodeGrantAsync(TClient client, List<Claim> c
3737
var grant = new AuthCodeTtlGrant
3838
{
3939
TimeToLive = client.AuthorizationCodeLifetime.Value,
40-
Claims = grantClaims.ToClaimAndValues(),
4140
ClientId = client.ClientId,
4241
RedirectUri = redirectUri,
4342
Scope = scope,
4443
Nonce = nonce,
4544
CodeChallenge = codeChallenge,
4645
CodeChallengeMethod = codeChallengeMethod
4746
};
47+
grant.Claims = new List<ClaimAndValues>();
48+
foreach (var gc in grantClaims.ToClaimAndValues())
49+
{
50+
try
51+
{
52+
await gc.ValidateObjectAsync();
53+
grant.Claims.Add(gc);
54+
}
55+
catch (Exception ex)
56+
{
57+
logger.Warning(ex, $"Unable to save claim '{gc.Claim}' in grant.");
58+
}
59+
}
4860
await grant.SetIdAsync(new AuthCodeTtlGrant.IdKey { TenantName = RouteBinding.TenantName, TrackName = RouteBinding.TrackName, Code = code });
4961
await tenantDataRepository.SaveAsync(grant);
5062

src/FoxIDs/Logic/Tracks/ClaimsDownLogic.cs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public async Task<List<Claim>> FromJwtToSamlClaimsAsync(IEnumerable<Claim> jwtCl
9494
{
9595
if (RouteBinding.AutoMapSamlClaims)
9696
{
97-
samlClaims.Add(new Claim(AddNewJwtBasedMappingReturnSaml(mappings, newMappings, jwtClaim.Type), jwtClaim.Value, jwtClaim.ValueType, jwtClaim.Issuer, jwtClaim.OriginalIssuer));
97+
samlClaims.Add(new Claim(await AddNewJwtBasedMappingReturnSamlAsync(mappings, newMappings, jwtClaim.Type), jwtClaim.Value, jwtClaim.ValueType, jwtClaim.Issuer, jwtClaim.OriginalIssuer));
9898
}
9999
else
100100
{
@@ -113,8 +113,7 @@ public async Task<List<Claim>> FromJwtToSamlClaimsAsync(IEnumerable<Claim> jwtCl
113113
}
114114
catch (Exception ex)
115115
{
116-
logger.Error(ex, "Failed to map JWT claims to SAML claims.");
117-
throw;
116+
throw new Exception("Failed to map JWT claims to SAML claims.", ex);
118117
}
119118
}
120119

@@ -178,7 +177,7 @@ public async Task<List<Claim>> FromSamlToJwtClaimsAsync(IEnumerable<Claim> samlC
178177
{
179178
if (RouteBinding.AutoMapSamlClaims)
180179
{
181-
jwtClaims.Add(new Claim(AddNewSamlBasedMappingReturnJwt(mappings, newMappings, samlClaim.Type), samlClaim.Value, samlClaim.ValueType, samlClaim.Issuer, samlClaim.OriginalIssuer));
180+
jwtClaims.Add(new Claim(await AddNewSamlBasedMappingReturnJwtAsync(mappings, newMappings, samlClaim.Type), samlClaim.Value, samlClaim.ValueType, samlClaim.Issuer, samlClaim.OriginalIssuer));
182181
}
183182
else
184183
{
@@ -198,8 +197,7 @@ public async Task<List<Claim>> FromSamlToJwtClaimsAsync(IEnumerable<Claim> samlC
198197
}
199198
catch (Exception ex)
200199
{
201-
logger.Error(ex, "Failed to map SAML claims to JWT claims.");
202-
throw;
200+
throw new Exception("Failed to map SAML claims to JWT claims.", ex);
203201
}
204202
}
205203

@@ -226,8 +224,7 @@ public List<string> FromSamlToJwtInfoClaimType(string samlClaimType)
226224
}
227225
catch (Exception ex)
228226
{
229-
logger.Error(ex, "Failed to map SAML claims to JWT claim types.");
230-
throw;
227+
throw new Exception("Failed to map SAML claims to JWT claim types.", ex);
231228
}
232229
}
233230

@@ -312,20 +309,30 @@ private List<ClaimMap> GetMappings(RouteBinding RouteBinding, bool toJwtClaims)
312309
}
313310

314311

315-
private string AddNewJwtBasedMappingReturnSaml(List<ClaimMap> mappings, List<ClaimMap> newMappings, string jwtClaim)
312+
private async Task<string> AddNewJwtBasedMappingReturnSamlAsync(List<ClaimMap> mappings, List<ClaimMap> newMappings, string jwtClaim)
316313
{
314+
var samlClaim = $"{Constants.SamlAutoMapClaimTypes.Namespace}{jwtClaim.Replace("_", "")}";
317315
var claimMap = new ClaimMap
318316
{
319317
JwtClaim = jwtClaim.ToLower(),
320-
SamlClaim = $"{Constants.SamlAutoMapClaimTypes.Namespace}{jwtClaim.Replace("_", "")}"
318+
SamlClaim = samlClaim
321319
};
322320
mappings.Add(claimMap);
323-
newMappings.Add(claimMap);
321+
322+
try
323+
{
324+
await claimMap.ValidateObjectAsync();
325+
newMappings.Add(claimMap);
326+
}
327+
catch (Exception ex)
328+
{
329+
logger.Warning(ex, $"Unable to map JWT claim '{jwtClaim}' to SAML 2.0 claim '{samlClaim}'.");
330+
}
324331

325332
return claimMap.SamlClaim;
326333
}
327334

328-
private string AddNewSamlBasedMappingReturnJwt(List<ClaimMap> mappings, List<ClaimMap> newMappings, string samlClaim)
335+
private async Task<string> AddNewSamlBasedMappingReturnJwtAsync(List<ClaimMap> mappings, List<ClaimMap> newMappings, string samlClaim)
329336
{
330337
string jwtClaim = null;
331338
var claimSplit = samlClaim.Split('/');
@@ -361,7 +368,16 @@ private string AddNewSamlBasedMappingReturnJwt(List<ClaimMap> mappings, List<Cla
361368
SamlClaim = samlClaim,
362369
};
363370
mappings.Add(claimMap);
364-
newMappings.Add(claimMap);
371+
372+
try
373+
{
374+
await claimMap.ValidateObjectAsync();
375+
newMappings.Add(claimMap);
376+
}
377+
catch (Exception ex)
378+
{
379+
logger.Warning(ex, $"Unable to map SAML 2.0 claim '{samlClaim}' to JWT claim '{jwtClaim}'.");
380+
}
365381

366382
return jwtClaim;
367383
}

0 commit comments

Comments
 (0)