Merge pull request #3544 from sbwalker/dev

comsider name and email claim values as optional
This commit is contained in:
Shaun Walker
2023-12-12 14:04:08 -05:00
committed by GitHub

View File

@ -184,35 +184,27 @@ namespace Oqtane.Extensions
JsonNode items = JsonNode.Parse(jsonclaims)!; JsonNode items = JsonNode.Parse(jsonclaims)!;
foreach (var item in items.AsArray()) foreach (var item in items.AsArray())
{ {
name = "";
email = "";
// id claim is required // id claim is required
if (!string.IsNullOrEmpty(idClaimType) && item[idClaimType] != null) if (!string.IsNullOrEmpty(idClaimType) && item[idClaimType] != null)
{ {
id = item[idClaimType].ToString(); id = item[idClaimType].ToString();
// name claim is optional // name claim is optional
if (!string.IsNullOrEmpty(nameClaimType)) if (!string.IsNullOrEmpty(nameClaimType) && item[nameClaimType] != null)
{ {
if (item[nameClaimType] != null) name = item[nameClaimType].ToString();
{
name = item[nameClaimType].ToString();
}
else
{
id = ""; // name claim was specified but was not provided
}
} }
// email claim is optional // email claim is optional
if (!string.IsNullOrEmpty(emailClaimType)) if (!string.IsNullOrEmpty(emailClaimType) && item[emailClaimType] != null)
{ {
if (item[emailClaimType] != null && EmailValid(item[emailClaimType].ToString(), context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:DomainFilter", ""))) if (EmailValid(item[emailClaimType].ToString(), context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:DomainFilter", "")))
{ {
email = item[emailClaimType].ToString().ToLower(); email = item[emailClaimType].ToString().ToLower();
} }
else
{
id = ""; // email claim was specified but was not provided or is invalid
}
} }
} }
if (!string.IsNullOrEmpty(id)) if (!string.IsNullOrEmpty(id))
@ -282,29 +274,22 @@ namespace Oqtane.Extensions
var nameClaimType = context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:NameClaimType", ""); var nameClaimType = context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:NameClaimType", "");
var emailClaimType = context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:EmailClaimType", ""); var emailClaimType = context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:EmailClaimType", "");
// parse claim values // parse claim values - id claim is required
id = context.Principal.FindFirstValue(idClaimType); // required id = context.Principal.FindFirstValue(idClaimType);
if (!string.IsNullOrEmpty(nameClaimType))
// name claim is optional
if (!string.IsNullOrEmpty(nameClaimType) && context.Principal.FindFirstValue(nameClaimType) != null)
{ {
if (context.Principal.FindFirstValue(nameClaimType) != null) name = context.Principal.FindFirstValue(nameClaimType);
{
name = context.Principal.FindFirstValue(nameClaimType);
}
else
{
id = ""; // name claim was specified but was not provided
}
} }
if (!string.IsNullOrEmpty(emailClaimType))
// email claim is optional
if (!string.IsNullOrEmpty(emailClaimType) && context.Principal.FindFirstValue(emailClaimType) != null)
{ {
if (context.Principal.FindFirstValue(emailClaimType) != null && EmailValid(context.Principal.FindFirstValue(emailClaimType), context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:DomainFilter", ""))) if (EmailValid(context.Principal.FindFirstValue(emailClaimType), context.HttpContext.GetSiteSettings().GetValue("ExternalLogin:DomainFilter", "")))
{ {
email = context.Principal.FindFirstValue(emailClaimType); email = context.Principal.FindFirstValue(emailClaimType);
} }
else
{
id = ""; // email claim was specified but was not provided or is invalid
}
} }
// validate user // validate user