-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get authorization policies to work client-side.
- Loading branch information
Showing
7 changed files
with
123 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 2 additions & 15 deletions
17
ControlR.Web.Client/Extensions/ClaimsPrincipalExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,16 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Security.Claims; | ||
using System.Security.Claims; | ||
|
||
namespace ControlR.Web.Client.Extensions; | ||
|
||
public static class ClaimsPrincipalExtensions | ||
{ | ||
public static bool IsAdministrator(this ClaimsPrincipal user) | ||
{ | ||
return | ||
user.TryGetClaim(ClaimNames.IsAdministrator, out var claimValue) && | ||
bool.TryParse(claimValue, out var isAdmin) && | ||
isAdmin; | ||
return user.HasClaim(x => x is { Type: ClaimNames.IsAdministrator }); | ||
} | ||
|
||
public static bool IsAuthenticated(this ClaimsPrincipal user) | ||
{ | ||
return user.Identity?.IsAuthenticated ?? false; | ||
} | ||
|
||
public static bool TryGetClaim( | ||
this ClaimsPrincipal user, | ||
string claimType, | ||
[NotNullWhen(true)] out string? claimValue) | ||
{ | ||
claimValue = user.Claims.FirstOrDefault(x => x.Type == claimType)?.Value ?? string.Empty; | ||
return !string.IsNullOrWhiteSpace(claimValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters