-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
151 additions
and
149 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
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
64 changes: 64 additions & 0 deletions
64
src/AspNetCore.Authorization.Permissions.Identity/IdentityBuilderExtensions.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
namespace AspNetCore.Authorization.Permissions.Identity | ||
{ | ||
using System; | ||
using JetBrains.Annotations; | ||
using Microsoft.AspNetCore.Identity; | ||
|
||
/// <summary> | ||
/// Extension methods for the <see cref="IdentityBuilderExtensions" /> type. | ||
/// </summary> | ||
[PublicAPI] | ||
public static class IdentityBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds the claims provider for the identity library. | ||
/// </summary> | ||
/// <param name="builder"></param> | ||
/// <returns></returns> | ||
public static IdentityBuilder AddIdentityClaimsProvider(this IdentityBuilder builder) | ||
{ | ||
return builder.AddIdentityClaimsProvider<PermissionsIdentityUser, PermissionsIdentityPermission, PermissionsIdentityTenant>(); | ||
} | ||
|
||
/// <summary> | ||
/// Adds the claims provider for the identity library. | ||
/// </summary> | ||
/// <param name="builder"></param> | ||
/// <returns></returns> | ||
public static IdentityBuilder AddIdentityClaimsProvider<TUser>(this IdentityBuilder builder) | ||
where TUser : class, IUser | ||
{ | ||
return builder.AddIdentityClaimsProvider<TUser, PermissionsIdentityPermission, PermissionsIdentityTenant>(); | ||
} | ||
|
||
/// <summary> | ||
/// Adds the claims provider for the identity library. | ||
/// </summary> | ||
/// <param name="builder"></param> | ||
/// <returns></returns> | ||
public static IdentityBuilder AddIdentityClaimsProvider<TUser, TPermission>(this IdentityBuilder builder) | ||
where TUser : class, IUser | ||
where TPermission : class, IPermission | ||
{ | ||
return builder.AddIdentityClaimsProvider<TUser, TPermission, PermissionsIdentityTenant>(); | ||
} | ||
|
||
/// <summary> | ||
/// Adds the claims provider for the identity library. | ||
/// </summary> | ||
/// <param name="builder"></param> | ||
/// <returns></returns> | ||
public static IdentityBuilder AddIdentityClaimsProvider<TUser, TPermission, TTenant>(this IdentityBuilder builder) | ||
where TUser : class, IUser | ||
where TPermission : class, IPermission | ||
where TTenant : class, ITenant | ||
{ | ||
Type identityClaimsProviderType = typeof(IdentityClaimsProvider<,,>) | ||
.MakeGenericType(typeof(TUser), typeof(TPermission), typeof(TTenant)); | ||
|
||
builder.Services.AddClaimsProvider(identityClaimsProviderType); | ||
|
||
return builder; | ||
} | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
src/AspNetCore.Authorization.Permissions.Identity/PermissionsBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
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
38 changes: 0 additions & 38 deletions
38
src/AspNetCore.Authorization.Permissions/PermissionsAuthenticationOptions.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,50 +1,12 @@ | ||
namespace AspNetCore.Authorization.Permissions | ||
{ | ||
using System; | ||
using AspNetCore.Authorization.Permissions.Abstractions; | ||
using Fluxera.Guards; | ||
using Fluxera.Utilities.Extensions; | ||
using JetBrains.Annotations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
/// <summary> | ||
/// The options for the permission authorization. | ||
/// </summary> | ||
[PublicAPI] | ||
public sealed class PermissionsAuthenticationOptions | ||
{ | ||
private readonly IServiceCollection services; | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="PermissionsAuthenticationOptions" /> type. | ||
/// </summary> | ||
/// <param name="services"></param> | ||
public PermissionsAuthenticationOptions(IServiceCollection services) | ||
{ | ||
this.services = services; | ||
} | ||
|
||
/// <summary> | ||
/// Adds the given claims provider type. | ||
/// </summary> | ||
/// <typeparam name="TProvider"></typeparam> | ||
/// <returns></returns> | ||
public void AddClaimsProvider<TProvider>() where TProvider : class, IClaimsProvider | ||
{ | ||
this.services.AddScoped<IClaimsProvider, TProvider>(); | ||
} | ||
|
||
/// <summary> | ||
/// Adds the given claims provider type. | ||
/// </summary> | ||
/// <param name="claimsProviderType"></param> | ||
/// <returns></returns> | ||
public void AddClaimsProvider(Type claimsProviderType) | ||
{ | ||
Guard.Against.False(claimsProviderType.Implements<IClaimsProvider>(), nameof(claimsProviderType), | ||
"The claims provider type must implement the IClaimsProvider contract."); | ||
|
||
this.services.AddScoped(typeof(IClaimsProvider), claimsProviderType); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.