Skip to content

Commit b8d0073

Browse files
committed
Fiks convert not null bool to bool? problem.
1 parent 1eb9dd4 commit b8d0073

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/ITfoxtec.Identity.Saml2/Util/GenericTypeConverter.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal static T ConvertElement<T>(XmlNode xmlNode)
7575
{
7676
return GenericConvertValue<T, NameIdPolicy>(new NameIdPolicy
7777
{
78-
AllowCreate = GenericConvertValue<bool?, string>(xmlNode.Attributes[Schemas.Saml2Constants.Message.AllowCreate]?.Value),
78+
AllowCreate = GenericConvertValueToNullable<bool>(xmlNode.Attributes[Schemas.Saml2Constants.Message.AllowCreate]?.Value),
7979
Format = xmlNode.Attributes[Schemas.Saml2Constants.Message.Format]?.Value,
8080
SPNameQualifier = xmlNode.Attributes[Schemas.Saml2Constants.Message.SpNameQualifier]?.Value
8181
});
@@ -109,5 +109,17 @@ static T GenericConvertValue<T, U>(U value)
109109
{
110110
return (T)Convert.ChangeType(value, typeof(T));
111111
}
112+
113+
static T? GenericConvertValueToNullable<T>(string value) where T : struct
114+
{
115+
if (string.IsNullOrWhiteSpace(value))
116+
{
117+
return null;
118+
}
119+
else
120+
{
121+
return (T)Convert.ChangeType(value, typeof(T));
122+
}
123+
}
112124
}
113125
}

test/TestWebAppCore/Controllers/AuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public IActionResult Login(string returnUrl = null)
3535
{
3636
//ForceAuthn = true,
3737
Subject = new Subject { NameID = new NameID { ID = "abcd" } },
38-
//NameIdPolicy = new NameIdPolicy { AllowCreate = true, Format = "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" },
38+
NameIdPolicy = new NameIdPolicy { AllowCreate = true, Format = "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" },
3939
//RequestedAuthnContext = new RequestedAuthnContext
4040
//{
4141
// Comparison = AuthnContextComparisonTypes.Exact,

test/TestWebAppCoreAzureKeyVault/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/TestWebAppCoreAzureKeyVault/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)