migration
All checks were successful
All checks were successful
This commit is contained in:
54
SimpleToolkit.Attributes/README.md
Normal file
54
SimpleToolkit.Attributes/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# SimpleToolkit.Attributes
|
||||
|
||||
### Set of helpers, class extensions, UI controls used in my other C# projects
|
||||
|
||||
SimpleToolkit is package of useful classes, helpers, extensions and UI controls, I use in my C# projects. Attributes subpackage contains class, method and property attributes.
|
||||
|
||||
---
|
||||
|
||||
## NuGet registry status
|
||||
|
||||
| Subpackage | Status |
|
||||
|-----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| **SimpleToolkit.Attributes** | [](https://www.nuget.org/packages/SimpleToolkit.Attributes/) |
|
||||
| SimpleToolkit.Extensions | [](https://www.nuget.org/packages/SimpleToolkit.Extensions/) |
|
||||
| SimpleToolkit.MVVM | [](https://www.nuget.org/packages/SimpleToolkit.MVVM/) |
|
||||
| SimpleToolkit.UI.Models | [](https://www.nuget.org/packages/SimpleToolkit.UI.Models/) |
|
||||
| SimpleToolkit.UI.WinUI.Behaviors | [](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Behaviors/) |
|
||||
| SimpleToolkit.UI.WinUI.Converters | [](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Converters/) |
|
||||
| SimpleToolkit.UI.WinUI.Controls | [](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Controls/) |
|
||||
| SimpleToolkit.UI.WinUI.Helpers | [](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Helpers/) |
|
||||
|
||||
## Features
|
||||
|
||||
- **RequiresClaimAttribute** - claim for ASP.NET Web API controller methods. Returns Forbidden result, when claim is not present.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Microsoft.AspNetCore.Mvc.Core 2.3.0
|
||||
|
||||
## Installation and usage
|
||||
|
||||
You can download package from official NuGet registry or .nupkg file itself from Releases tab.
|
||||
|
||||
**CLI:**
|
||||
|
||||
```
|
||||
dotnet add package SimpleToolkit.Attributes
|
||||
```
|
||||
|
||||
**Package reference in .csproj file:**
|
||||
|
||||
```
|
||||
<PackageReference Include="SimpleToolkit.Attributes" Version="<version>" />
|
||||
```
|
||||
|
||||
## Attribution and contribution
|
||||
|
||||
This project is open source on MIT License, so you can just copy and upload again to your repository. But according to the license, you must include information about the original author. You can find license [here](https://repos.mateuszskoczek.com/SimpleToolkit/SimpleToolkit.Attributes/src/branch/main/LICENSE).
|
||||
|
||||
However, the preferred way to contribute would be to propose improvements in a pull request, through issues, or through other means of communication.
|
||||
|
||||
**Other sources:**
|
||||
|
||||
- Icon by [Icons8](icons8.com)
|
||||
30
SimpleToolkit.Attributes/RequiresClaimAttribute.cs
Normal file
30
SimpleToolkit.Attributes/RequiresClaimAttribute.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SimpleToolkit.Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
||||
public class RequiresClaimAttribute : Attribute, IAuthorizationFilter
|
||||
{
|
||||
private readonly Predicate<Claim> _predicate;
|
||||
|
||||
public RequiresClaimAttribute(Predicate<Claim> predicate)
|
||||
{
|
||||
_predicate = predicate;
|
||||
}
|
||||
|
||||
public void OnAuthorization(AuthorizationFilterContext context)
|
||||
{
|
||||
if (!context.HttpContext.User.HasClaim(_predicate))
|
||||
{
|
||||
context.Result = new ForbidResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
SimpleToolkit.Attributes/SimpleToolkit.Attributes.csproj
Normal file
32
SimpleToolkit.Attributes/SimpleToolkit.Attributes.csproj
Normal file
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Title>SimpleToolkit.Attributes</Title>
|
||||
<Authors>Mateusz Skoczek</Authors>
|
||||
<Copyright>Mateusz Skoczek</Copyright>
|
||||
<PackageProjectUrl>https://repos.mateuszskoczek.com/SimpleToolkit/</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://repos.mateuszskoczek.com/SimpleToolkit/SimpleToolkit.Attributes/src/branch/main/LICENSE</PackageLicenseUrl>
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
<RepositoryUrl>https://repos.mateuszskoczek.com/SimpleToolkit/SimpleToolkit.Attributes</RepositoryUrl>
|
||||
<Description>Set of helpers, class extensions, UI controls used in my other C# projects - Class, method and property attributes</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="icon.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
<None Update="README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
BIN
SimpleToolkit.Attributes/icon.png
Normal file
BIN
SimpleToolkit.Attributes/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Reference in New Issue
Block a user