From 6b4c92eca24c1a9fcddf3b1f0e1616021e3e2f8b Mon Sep 17 00:00:00 2001 From: pfvatterott Date: Tue, 4 Mar 2025 14:16:11 -0700 Subject: [PATCH 1/3] Support for OAuth claimsPrincipal --- PropelAuth/User.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/PropelAuth/User.cs b/PropelAuth/User.cs index 6c6291e..584f08c 100644 --- a/PropelAuth/User.cs +++ b/PropelAuth/User.cs @@ -170,9 +170,17 @@ private string ExtractUserId(ClaimsPrincipal claimsPrincipal) return userId; } - private string ExtractEmail(ClaimsPrincipal claimsPrincipal) + private string ExtractEmail(ClaimsPrincipal claimsPrincipal) { - string? email = claimsPrincipal.FindFirstValue(ClaimTypes.Email); + string? email = string.Empty; + + if (claimsPrincipal.FindFirstValue(ClaimTypes.Email) != null) { + email = claimsPrincipal.FindFirstValue(ClaimTypes.Email); + } + else if (claimsPrincipal.Claims.First(c => c.Type == "email")?.Value != null) { + email = claimsPrincipal.Claims.First(c => c.Type == "email")?.Value; + }; + if (string.IsNullOrEmpty(email)) { throw new ArgumentException($"Required claim '{ClaimTypes.Email}' is missing or empty", From f2b3fa326b4a265a13ed1162fcad3fd371b481a7 Mon Sep 17 00:00:00 2001 From: pfvatterott Date: Tue, 4 Mar 2025 14:17:27 -0700 Subject: [PATCH 2/3] Update PropelAuth.csproj --- PropelAuth/PropelAuth.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PropelAuth/PropelAuth.csproj b/PropelAuth/PropelAuth.csproj index dfb7739..8b7865a 100644 --- a/PropelAuth/PropelAuth.csproj +++ b/PropelAuth/PropelAuth.csproj @@ -7,7 +7,7 @@ PropelAuth - 0.0.1 + 0.0.4 PropelAuth PropelAuth Official .NET SDK for PropelAuth authentication and authorization From 3d0b04a58ec20fbdeb80ce52572f78f78202ccff Mon Sep 17 00:00:00 2001 From: pfvatterott Date: Tue, 4 Mar 2025 15:53:44 -0700 Subject: [PATCH 3/3] Update User.cs --- PropelAuth/User.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/PropelAuth/User.cs b/PropelAuth/User.cs index 584f08c..3932b03 100644 --- a/PropelAuth/User.cs +++ b/PropelAuth/User.cs @@ -170,20 +170,13 @@ private string ExtractUserId(ClaimsPrincipal claimsPrincipal) return userId; } - private string ExtractEmail(ClaimsPrincipal claimsPrincipal) + private string ExtractEmail(ClaimsPrincipal claimsPrincipal) { - string? email = string.Empty; - - if (claimsPrincipal.FindFirstValue(ClaimTypes.Email) != null) { - email = claimsPrincipal.FindFirstValue(ClaimTypes.Email); - } - else if (claimsPrincipal.Claims.First(c => c.Type == "email")?.Value != null) { - email = claimsPrincipal.Claims.First(c => c.Type == "email")?.Value; - }; + string? email = claimsPrincipal.FindFirstValue("email") ?? claimsPrincipal.FindFirstValue(ClaimTypes.Email); if (string.IsNullOrEmpty(email)) { - throw new ArgumentException($"Required claim '{ClaimTypes.Email}' is missing or empty", + throw new ArgumentException($"Required claim 'email' is missing or empty", nameof(claimsPrincipal)); }