Skip to content

Commit

Permalink
feat: remove dependency to Identity.Web
Browse files Browse the repository at this point in the history
  • Loading branch information
loekensgard committed Nov 16, 2023
1 parent c2a86a3 commit 8a51bc4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Identity.Web" Version="2.15.3" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System.Security.Claims;

namespace Intility.Authorization.Azure.GuestPolicies;

Expand All @@ -16,8 +17,6 @@ public static class DenyGuestsExtensions
/// <returns>Services.</returns>
public static IServiceCollection AddDenyGuestsAuthorization(this IServiceCollection services)
{
services.AddAuthorization();

services.TryAddEnumerable(ServiceDescriptor.Singleton<IAuthorizationHandler, DenyGuestsAuthorizationsHandler>());

return services;
Expand All @@ -36,4 +35,17 @@ public static AuthorizationPolicyBuilder DenyGuests(this AuthorizationPolicyBuil

return authorizationPolicyBuilder;
}

/// <summary>
/// Returns the value for the first claim of the specified type, otherwise null if the claim is not present.
/// </summary>
/// <param name="principal">The <see cref="ClaimsPrincipal"/> instance this method extends.</param>
/// <param name="claimType">The claim type whose first value should be returned.</param>
/// <returns>The value of the first instance of the specified claim type, or null if the claim is not present.</returns>
internal static string? FindFirstValue(this ClaimsPrincipal principal, string claimType)
{
ArgumentNullException.ThrowIfNull(principal);
var claim = principal.FindFirst(claimType);
return claim?.Value;
}
}

0 comments on commit 8a51bc4

Please sign in to comment.