![]() |
VOOZH | about |
dotnet add package WebApiSkeleton.Security --version 1.1.2
NuGet\Install-Package WebApiSkeleton.Security -Version 1.1.2
<PackageReference Include="WebApiSkeleton.Security" Version="1.1.2" />
<PackageVersion Include="WebApiSkeleton.Security" Version="1.1.2" />Directory.Packages.props
<PackageReference Include="WebApiSkeleton.Security" />Project file
paket add WebApiSkeleton.Security --version 1.1.2
#r "nuget: WebApiSkeleton.Security, 1.1.2"
#:package WebApiSkeleton.Security@1.1.2
#addin nuget:?package=WebApiSkeleton.Security&version=1.1.2Install as a Cake Addin
#tool nuget:?package=WebApiSkeleton.Security&version=1.1.2Install as a Cake Tool
WebApiSkeleton.Security is a NuGet package that provides tooling for authentication and authorization in .NET
application or as a separate service.
WebApiSkeleton.Security.Core - contains base models and abstractions that are used to implement core functionality,
such as:
WebApiSkeleton.Security - security core implementation that is based on MediatR and other WebApiSkeleton
MediatR-related packages. The main features are:
NOTE: Core module does not make any validation or existence checks. All validation must be made in core implementations.
Required core dependencies are added to DI container by using AddSecurityCore method. All configuration is done by
modifying object.
The following settings are required and will throw if not specified or configured with errors:
RedisConnectionSettings - contains the address of Redis database and database number to use;DatabaseOptions - DbContext configuration action and the setting of cross-request MediatR transactions (highly
recommended to always be true);JwtSettings - JWT token settings that are used in creation process. Encryption key is required if UseJwtEncryption
is true on configuration Has default values for some fields
in TokenValidationParameters such as:
IssuerSigningKey will always automatically be set to SymmetricSecurityKey using provided SigningKey;ValidateIssuerSigningKey will always be true;ValidateLifetime will always be true;ClockSkew will always be set to TimeSpan.Zero;UseJwtEncryption is true in configuration, then TokenDecryptionKey will always automatically be set
to SymmetricSecurityKey using provided EncryptionKey;PasswordEncryptionKey - encryption key that is used for password hashingSettings with default values that can be overriden if needed:
IncludeUserClaimsInJwt - default is false. Not recommended to use if users will have too much claims as JWT token
would not fit in cookie;UseJwtEncryption - default is false. Highly recommended to use but disabled for more clear debugging and testing of
the JWT's;ValidationSettings - settings to validate usernames and passwords (not used in core module, left to use in
implementations using the core).
VerificationSettings - settings of email verification code. Verification code type and time to live can be set.
Required MediatR implementation dependencies are added to DI container by using AddSecurityMediatR method. The one
setting that can be changed is ContractPermissionStorageSettings that defines contract authorization requirements are
stored in database or not.
NOTE: this is the only one method that automatically adds the bruteforce detection pipeline behavior
for AuthorizationCommand. If you want to apply any pipeline behaviors before bruteforce check then apply them before
calling this method.
There are two ways to add Permission pipeline behaviors to DI to work correctly:
AddPermissionPipelineBehaviorsForRequestsInAssemblies extension method on IServiceProvider. This way passed
assemblies will be scanned for classes (or records) that implement IAuthorizedRequest<T> interface and automatically
add them to DI. If non-generic interface used then the call will throw an InvalidOperationException.
PermissionBehavior for request is automatically added, so it is highly recommended to mind
the order of IPipelineBehavior implementations added to DI.PermissionBehavior implementation type by
using PermissionBehaviorCreator. GetPermissionPipelineBehaviorForRequest method returns pipelineBehavior as a
service type and permissionBehavior as implementation type. After the tuple is returned, it is possible to manually
add pipelines in DI in the required order.MediatR implementation module contains validators for all of the commands using FluentValidation that are
automatically added to DI container.
Although, ValidationBehavior from WebApiSkeleton.Contracts.Validation is not automatically added and must be added
manually using methods found
in documentation.
NOTE: It is highly recommended to add ValidationBehavior after PermissionBehavior because of performance and
security reasons.
Authentication and authorization for requests are automatically managed
by by
using abstraction.
The identity model is provided by implementation
of .
There is no default implementation within WebApiSkeleton.Security modules. As an example there
is for ASP.NET Core
that gets the UserIdentity from HttpContext.
NOTE: if there is no implementation for IUserIdentityProvider
registered, is
always returned.
Using core package, all interaction is done by using . These services do not implement any validity checks, so database-related exception are likely to be thrown if violating indexes and rules.
MediatR implementation module has all operations implemented in .
All validation is done on request execution and will return faulted Result<T> if something is gone wrong.
NOTE: for validation to work, validation must be correctly configured.
Permission can be granted to any user or role with
corresponding . Restrict permission on
any of entities completely forbids the usage of this permission (even if it is Allowed in any other).
is the user-defined permission
requirement. It has a type name that defines what it is used for. Key property defines the entity which is given the
permission.
MediatR request authorization requirements can be added in two ways:
[SecurityRequirements(RequiredPermissions = ["SetUserPassword"], RequiredRoles = ["SecurityAdmin"])]
public sealed record SetUserPasswordCommand(UserLoginOrIdFinder UserLoginOrId, string Password) : IAuthorizedRequest<None>, IValidatableRequest<None>;
StoreContractPermissions is set to true, permissions for contract names can be persisted in database and then
used in PermissionBehavior to get required permissions. NOTE: in this case, contract permission is a custom
permission type with default type name "ContractPermission", which can be changed in CustomPermissionTypeName
property.Example projects for the service using WebApiSkeleton.Security MediatR implementation with different SQL providers can
be found in .
All projects are versioned using following format: major.minor.patch. Versioning rules for all projects:
patch needs to be incremented when any minor change is made to the project, such as bugfixes or small
project-specific features addedminor needs to be incremented when new template-wide feature is implemented. In this case all of the projects must
have the same version setmajor needs to be incremented when the WebApiSkeleton template has experienced significant changes, that need to
upgrade all of the template packages. In this case all of the projects must
have the same version set| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.