From 270f9aed091c44b23386385bb0bad03a2a43242c Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:42:37 -0500 Subject: [PATCH] Drop UserInfo classes (#469) --- .../BlazorWebAppOidc.Client/UserInfo.cs | 31 ------------------- .../BlazorWebAppOidc.Client/UserInfo.cs | 31 ------------------- 2 files changed, 62 deletions(-) delete mode 100644 9.0/BlazorWebAppOidc/BlazorWebAppOidc.Client/UserInfo.cs delete mode 100644 9.0/BlazorWebAppOidcBff/BlazorWebAppOidc.Client/UserInfo.cs diff --git a/9.0/BlazorWebAppOidc/BlazorWebAppOidc.Client/UserInfo.cs b/9.0/BlazorWebAppOidc/BlazorWebAppOidc.Client/UserInfo.cs deleted file mode 100644 index 78f5e0a0..00000000 --- a/9.0/BlazorWebAppOidc/BlazorWebAppOidc.Client/UserInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Security.Claims; - -namespace BlazorWebAppOidc.Client; - -// Add properties to this class and update the server and client AuthenticationStateProviders -// to expose more information about the authenticated user to the client. -public sealed class UserInfo -{ - public required string UserId { get; init; } - public required string Name { get; init; } - - public const string UserIdClaimType = "sub"; - public const string NameClaimType = "name"; - - public static UserInfo FromClaimsPrincipal(ClaimsPrincipal principal) => - new() - { - UserId = GetRequiredClaim(principal, UserIdClaimType), - Name = GetRequiredClaim(principal, NameClaimType), - }; - - public ClaimsPrincipal ToClaimsPrincipal() => - new(new ClaimsIdentity( - [new(UserIdClaimType, UserId), new(NameClaimType, Name)], - authenticationType: nameof(UserInfo), - nameType: NameClaimType, - roleType: null)); - - private static string GetRequiredClaim(ClaimsPrincipal principal, string claimType) => - principal.FindFirst(claimType)?.Value ?? throw new InvalidOperationException($"Could not find required '{claimType}' claim."); -} diff --git a/9.0/BlazorWebAppOidcBff/BlazorWebAppOidc.Client/UserInfo.cs b/9.0/BlazorWebAppOidcBff/BlazorWebAppOidc.Client/UserInfo.cs deleted file mode 100644 index 78f5e0a0..00000000 --- a/9.0/BlazorWebAppOidcBff/BlazorWebAppOidc.Client/UserInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Security.Claims; - -namespace BlazorWebAppOidc.Client; - -// Add properties to this class and update the server and client AuthenticationStateProviders -// to expose more information about the authenticated user to the client. -public sealed class UserInfo -{ - public required string UserId { get; init; } - public required string Name { get; init; } - - public const string UserIdClaimType = "sub"; - public const string NameClaimType = "name"; - - public static UserInfo FromClaimsPrincipal(ClaimsPrincipal principal) => - new() - { - UserId = GetRequiredClaim(principal, UserIdClaimType), - Name = GetRequiredClaim(principal, NameClaimType), - }; - - public ClaimsPrincipal ToClaimsPrincipal() => - new(new ClaimsIdentity( - [new(UserIdClaimType, UserId), new(NameClaimType, Name)], - authenticationType: nameof(UserInfo), - nameType: NameClaimType, - roleType: null)); - - private static string GetRequiredClaim(ClaimsPrincipal principal, string claimType) => - principal.FindFirst(claimType)?.Value ?? throw new InvalidOperationException($"Could not find required '{claimType}' claim."); -}