Skip to content

Commit d3e990d

Browse files
committed
Support NameID without a Format.
Saml2AuthnResponse do not add "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" as default NameID Format.
1 parent 6036115 commit d3e990d

File tree

8 files changed

+22
-16
lines changed

8 files changed

+22
-16
lines changed

src/ITfoxtec.Identity.Saml2.Mvc/ITfoxtec.Identity.Saml2.Mvc.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<PackageTags>SAML SAML 2.0 SAML2.0 SAML2 SAML 2 SAML-P SAMLP SSO Identity Provider (IdP) and Relying Party (RP) Authentication Metadata OIOSAML NemLog-in ASP.NET MVC</PackageTags>
1515
<NeutralLanguage>en-US</NeutralLanguage>
1616
<PackageIconUrl>https://itfoxtec.com/favicon.ico</PackageIconUrl>
17-
<AssemblyVersion>4.2.0.0</AssemblyVersion>
18-
<FileVersion>4.2.0.0</FileVersion>
17+
<AssemblyVersion>4.3.0.0</AssemblyVersion>
18+
<FileVersion>4.3.0.0</FileVersion>
1919
<Copyright>Copyright © 2021</Copyright>
20-
<Version>4.2.0</Version>
20+
<Version>4.3.0</Version>
2121
<SignAssembly>true</SignAssembly>
2222
<AssemblyOriginatorKeyFile>ITfoxtec.SAML2.snk</AssemblyOriginatorKeyFile>
2323
<DelaySign>false</DelaySign>

src/ITfoxtec.Identity.Saml2.MvcCore/ITfoxtec.Identity.Saml2.MvcCore.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
<PackageTags>SAML SAML 2.0 SAML2.0 SAML2 SAML 2 SAML-P SAMLP SSO Identity Provider (IdP) Relying Party (RP) Authentication Metadata OIOSAML NemLog-in ASP.NET MVC Core</PackageTags>
1717
<NeutralLanguage>en-US</NeutralLanguage>
1818
<PackageIconUrl>https://itfoxtec.com/favicon.ico</PackageIconUrl>
19-
<AssemblyVersion>4.2.0.0</AssemblyVersion>
20-
<FileVersion>4.2.0.0</FileVersion>
19+
<AssemblyVersion>4.3.0.0</AssemblyVersion>
20+
<FileVersion>4.3.0.0</FileVersion>
2121
<Copyright>Copyright © 2021</Copyright>
22-
<Version>4.2.0</Version>
22+
<Version>4.3.0</Version>
2323
<SignAssembly>true</SignAssembly>
2424
<AssemblyOriginatorKeyFile>ITfoxtec.SAML2.snk</AssemblyOriginatorKeyFile>
2525
<DelaySign>false</DelaySign>

src/ITfoxtec.Identity.Saml2/ITfoxtec.Identity.Saml2.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Tested for compliance with AD FS, Azure AD and Azure AD B2C. Furthermore, the Da
2323
<PackageTags>SAML SAML 2.0 SAML2.0 SAML2 SAML 2 SAML-P SAMLP SSO Identity Provider (IdP) Relying Party (RP) Authentication Metadata OIOSAML NemLog-in</PackageTags>
2424
<NeutralLanguage>en-US</NeutralLanguage>
2525
<PackageIconUrl>https://itfoxtec.com/favicon.ico</PackageIconUrl>
26-
<AssemblyVersion>4.2.0.0</AssemblyVersion>
27-
<FileVersion>4.2.0.0</FileVersion>
26+
<AssemblyVersion>4.3.0.0</AssemblyVersion>
27+
<FileVersion>4.3.0.0</FileVersion>
2828
<Copyright>Copyright © 2021</Copyright>
29-
<Version>4.2.0</Version>
29+
<Version>4.3.0</Version>
3030
<SignAssembly>true</SignAssembly>
3131
<AssemblyOriginatorKeyFile>ITfoxtec.SAML2.snk</AssemblyOriginatorKeyFile>
3232
<DelaySign>false</DelaySign>

src/ITfoxtec.Identity.Saml2/Request/Saml2AuthnResponse.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ private void AddNameIdFormat()
184184
if (NameId == null) throw new ArgumentNullException("NameId property");
185185

186186
Saml2SecurityToken.Assertion.Subject.NameId = NameId;
187-
if (Saml2SecurityToken.Assertion.Subject.NameId.Format == null)
188-
{
189-
Saml2SecurityToken.Assertion.Subject.NameId.Format = Schemas.NameIdentifierFormats.Persistent;
190-
}
191187
}
192188

193189
private void AddSubjectConfirmation(Saml2SubjectConfirmation subjectConfirmation)

src/ITfoxtec.Identity.Saml2/Request/Saml2LogoutRequest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ public Saml2LogoutRequest(Saml2Configuration config, ClaimsPrincipal currentPrin
4848
var identity = currentPrincipal.Identities.First();
4949
if (identity.IsAuthenticated)
5050
{
51-
NameId = new Saml2NameIdentifier(ReadClaimValue(identity, Saml2ClaimTypes.NameId), new Uri(ReadClaimValue(identity, Saml2ClaimTypes.NameIdFormat, false)));
51+
var nameIdFormat = ReadClaimValue(identity, Saml2ClaimTypes.NameIdFormat, false);
52+
if (string.IsNullOrEmpty(nameIdFormat))
53+
{
54+
NameId = new Saml2NameIdentifier(ReadClaimValue(identity, Saml2ClaimTypes.NameId));
55+
}
56+
else
57+
{
58+
NameId = new Saml2NameIdentifier(ReadClaimValue(identity, Saml2ClaimTypes.NameId), new Uri(nameIdFormat));
59+
60+
}
5261
SessionIndex = ReadClaimValue(identity, Saml2ClaimTypes.SessionIndex, false);
5362
}
5463
}

test/TestIdPCore/Controllers/AuthController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ private IActionResult LoginResponse(Saml2Id inResponseTo, Saml2StatusCodes statu
109109

110110
var claimsIdentity = new ClaimsIdentity(claims);
111111
saml2AuthnResponse.NameId = new Saml2NameIdentifier(claimsIdentity.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).Select(c => c.Value).Single(), NameIdentifierFormats.Persistent);
112+
//saml2AuthnResponse.NameId = new Saml2NameIdentifier(claimsIdentity.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).Select(c => c.Value).Single());
112113
saml2AuthnResponse.ClaimsIdentity = claimsIdentity;
113114

114115
var token = saml2AuthnResponse.CreateSecurityToken(relyingParty.Issuer, subjectConfirmationLifetime: 5, issuedTokenLifetime: 60);

test/TestWebAppCore/wwwroot/css/site.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/TestWebAppCore/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)