Skip to content

Commit

Permalink
+Fixed ASP.NET Core Extension Bug
Browse files Browse the repository at this point in the history
+Fixed a critical bug preventing MongoDB Extension Service Iinitialization
  • Loading branch information
rainxh11 committed May 25, 2022
1 parent af02a38 commit 06b6ad4
Show file tree
Hide file tree
Showing 43 changed files with 892 additions and 108 deletions.
6 changes: 4 additions & 2 deletions Revoke.NET.Akavache/Revoke.NET.Akavache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>1.0.4</Version>
<Version>1.0.6</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET Akavache Store Extension</Description>
Expand All @@ -19,6 +19,8 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>revoke;jwt;token;permission;deny;blacklist;aspnet;logout;expiration;invalidate;ip;mongo;mongodb;store</PackageTags>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,7 +29,7 @@
<None Include="LICENSE" Pack="true" PackagePath="" />
<PackageReference Include="akavache" Version="8.1.1" />
<PackageReference Include="akavache.sqlite3" Version="8.1.1" />
<PackageReference Include="Revoke.NET" Version="1.0.3" />
<PackageReference Include="Revoke.NET" Version="1.0.5" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
Expand Down
39 changes: 0 additions & 39 deletions Revoke.NET.AspNetCore/Revoke - Backup.NET.AspNetCore.csproj

This file was deleted.

11 changes: 6 additions & 5 deletions Revoke.NET.AspNetCore/Revoke.NET.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>1.0.5</Version>
<Version>1.0.7</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET ASP.NET Core Extension</Description>
Expand All @@ -20,16 +20,17 @@
<PackageTags>revoke;jwt;token;permission;deny;blacklist;aspnet;logout;expiration;invalidate;ip</PackageTags>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
<Nullable>annotations</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="assets\revoke.net.png" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="LICENSE" Pack="true" PackagePath="" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Revoke.NET" Version="1.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Revoke.NET" Version="1.0.5" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Revoke.NET.AspNetCore/RevokeHttpMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (await store.IsRevoked(revokeKey))
{
var item = await store.Get<IBlackListItem>(revokeKey);

logger.LogInformation(
$"[Revoke.NET] Revoked Access to key: '{revokeKey}', Blacklisting will be lifted on {item.ExpireOn}");
if (responseFunc != null)
{
await responseFunc(context.Response);
Expand All @@ -72,6 +68,10 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
}


logger.LogInformation(
$"[Revoke.NET] Revoked Access to key: '{revokeKey}'");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Revoke.NET" Version="1.0.3" />
<PackageReference Include="Revoke.NET.AspNetCore" Version="1.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
</ItemGroup>

Expand Down
14 changes: 7 additions & 7 deletions Revoke.NET.MongoDB/MongoBlackListStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Revoke.NET.MongoDB
{
public class MongoBlackListStore : IBlackListStore
{
private readonly IMongoCollection<IBlackListItem> blacklist;
private readonly IMongoCollection<BlackListItem> blacklist;

private MongoBlackListStore(IMongoCollection<IBlackListItem> blacklist)
private MongoBlackListStore(IMongoCollection<BlackListItem> blacklist)
{
this.blacklist = blacklist;
}
Expand All @@ -22,15 +22,15 @@ public static async Task<IBlackListStore> CreateStoreAsync(string dbName,

var db = client.GetDatabase(dbName);

var keyIndex = Builders<IBlackListItem>.IndexKeys.Ascending(x => x.Key);
var ttlIndex = Builders<IBlackListItem>.IndexKeys.Ascending(x => x.ExpireOn);
var keyIndex = Builders<BlackListItem>.IndexKeys.Ascending(x => x.Key);
var ttlIndex = Builders<BlackListItem>.IndexKeys.Ascending(x => x.ExpireOn);

var collection = db.GetCollection<IBlackListItem>(nameof(IBlackListItem));
var collection = db.GetCollection<BlackListItem>(nameof(BlackListItem));

await collection.Indexes.CreateOneAsync(
new CreateIndexModel<IBlackListItem>(keyIndex, new CreateIndexOptions() { Unique = true }));
new CreateIndexModel<BlackListItem>(keyIndex, new CreateIndexOptions() { Unique = true }));
await collection.Indexes.CreateOneAsync(
new CreateIndexModel<IBlackListItem>(keyIndex,
new CreateIndexModel<BlackListItem>(ttlIndex,
new CreateIndexOptions() { ExpireAfter = TimeSpan.FromMinutes(1) }));

return new MongoBlackListStore(collection);
Expand Down
5 changes: 3 additions & 2 deletions Revoke.NET.MongoDB/Revoke.NET.MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>1.0.3</Version>
<Version>1.0.7</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET MongoDB Store Extension</Description>
Expand All @@ -19,14 +19,15 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>revoke;jwt;token;permission;deny;blacklist;aspnet;logout;expiration;invalidate;ip;mongo;mongodb;store</PackageTags>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Include="assets\revoke.net.png" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="LICENSE" Pack="true" PackagePath="" />
<PackageReference Include="MongoDB.Driver" Version="2.15.1" />
<PackageReference Include="Revoke.NET" Version="1.0.3" />
<PackageReference Include="Revoke.NET" Version="1.0.5" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Revoke.NET.MonkeyCache/Revoke.NET.EasyCaching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

</Project>
14 changes: 9 additions & 5 deletions Revoke.NET.Redis/RedisBlackListStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Task DeleteExpired()
public async Task<T> Get<T>(string key) where T : IBlackListItem
{
var value = await blacklist.StringGetAsync(key);
return JsonSerializer.Deserialize<T>(value.ToString());
return JsonSerializer.Deserialize<T>((string)value.Box());
}

public async Task<IEnumerable<T>> GetAll<T>() where T : IBlackListItem
Expand All @@ -60,7 +60,7 @@ public async Task<IEnumerable<T>> GetAll<T>() where T : IBlackListItem
foreach (var key in servers.SelectMany(x => x.Keys()))
{
var value = await blacklist.StringGetAsync(key);
temp.Add(JsonSerializer.Deserialize<T>(value.ToString()));
temp.Add(JsonSerializer.Deserialize<T>((string)value.Box()));
}

return temp;
Expand All @@ -74,19 +74,23 @@ public async Task<bool> IsRevoked(string key)

public async Task<bool> Revoke(string key)
{
var value = await blacklist.StringSetAndGetAsync(key, key);
var value = await blacklist.StringSetAndGetAsync(key,
JsonSerializer.Serialize(new BlackListItem(key, DateTimeOffset.MaxValue)));
return value.HasValue;
}

public async Task<bool> Revoke(string key, TimeSpan expireAfter)
{
var value = await blacklist.StringSetAndGetAsync(key, key, expireAfter);
var value = await blacklist.StringSetAndGetAsync(key,
JsonSerializer.Serialize(new BlackListItem(key, DateTimeOffset.MaxValue)), expireAfter);
return value.HasValue;
}

public async Task<bool> Revoke(string key, DateTimeOffset expireOn)
{
var value = await blacklist.StringSetAndGetAsync(key, key, expireOn - DateTimeOffset.Now);
var value = await blacklist.StringSetAndGetAsync(key,
JsonSerializer.Serialize(new BlackListItem(key, DateTimeOffset.MaxValue)),
expireOn - DateTimeOffset.Now);
return value.HasValue;
}

Expand Down
8 changes: 6 additions & 2 deletions Revoke.NET.Redis/Revoke.NET.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET Redis Store Extension</Description>
Expand All @@ -19,15 +19,19 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>revoke;jwt;token;permission;deny;blacklist;aspnet;logout;expiration;invalidate;ip;mongo;redis;stackexchange;store</PackageTags>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Include="assets\revoke.net.png" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="LICENSE" Pack="true" PackagePath="" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Revoke.NET" Version="1.0.4" />
<PackageReference Include="StackExchange.Redis" Version="2.5.61" />
<PackageReference Include="System.Text.Json" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.4" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Revoke.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Revoke.NET.Redis", "Revoke.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Revoke.NET.AspNetCore", "Revoke.NET.AspNetCore\Revoke.NET.AspNetCore.csproj", "{54D90C45-FE00-4AB3-9369-8BBDA03863BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{BC5B0041-DDA4-470A-92AD-9B6AB67E120D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -51,6 +53,10 @@ Global
{54D90C45-FE00-4AB3-9369-8BBDA03863BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54D90C45-FE00-4AB3-9369-8BBDA03863BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54D90C45-FE00-4AB3-9369-8BBDA03863BA}.Release|Any CPU.Build.0 = Release|Any CPU
{BC5B0041-DDA4-470A-92AD-9B6AB67E120D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC5B0041-DDA4-470A-92AD-9B6AB67E120D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC5B0041-DDA4-470A-92AD-9B6AB67E120D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC5B0041-DDA4-470A-92AD-9B6AB67E120D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
37 changes: 0 additions & 37 deletions Revoke.NET/Revoke - Backup.NET.csproj

This file was deleted.

9 changes: 5 additions & 4 deletions Revoke.NET/Revoke.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>.NET Utility to blacklist and revoke access to stuff</Description>
Expand All @@ -19,14 +19,15 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageTags>revoke;jwt;token;permission;deny;blacklist;aspnet;logout;expiration;invalidate;ip</PackageTags>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="assets\revoke.net.png" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="LICENSE" Pack="true" PackagePath="" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions Test/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Revoke.NET;
using Revoke.NET.Redis;

var store = await RedisBlackListStore.CreateStoreAsync("localhost");

await store.Revoke("Ahmed", DateTimeOffset.MaxValue);

var item = await store.Get<BlackListItem>("Ahmed");

Console.WriteLine(item.Key);

Console.ReadKey();
16 changes: 16 additions & 0 deletions Test/Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Revoke.NET" Version="1.0.5" />
<PackageReference Include="Revoke.NET.Redis" Version="1.0.6" />
</ItemGroup>

</Project>
Binary file added assets/revoke.net.ico
Binary file not shown.
1 change: 1 addition & 0 deletions docfx/_site/.dependencymap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"dependencies":{"index.md":[{"source":"toc.yml","type":"metadata"}],"toc.yml":[{"source":"index.md","type":"file"}]}}
Loading

0 comments on commit 06b6ad4

Please sign in to comment.