Skip to content

Commit

Permalink
Merge pull request #3 from jeffward01/file-scoped-namespaces
Browse files Browse the repository at this point in the history
File scoped namespaces
  • Loading branch information
rainxh11 authored Oct 13, 2022
2 parents fc9bfc9 + 2ae0880 commit bf17c1e
Show file tree
Hide file tree
Showing 31 changed files with 1,072 additions and 1,018 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/

# JetBrains Rider cache/options/config directory
.idea

# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down
147 changes: 73 additions & 74 deletions Revoke.NET.Akavache/AkavacheBlackList.cs
Original file line number Diff line number Diff line change
@@ -1,103 +1,102 @@
using System;
using System.Collections.Generic;
namespace Revoke.NET.Akavache;

using System;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Akavache;
using Registrations = Akavache.Registrations;
using global::Akavache;

namespace Revoke.NET.Akavache
public class AkavacheBlackList : IBlackList
{
public class AkavacheBlackList : IBlackList
private static TimeSpan? _defaultTtl;
private readonly IBlobCache _blackList;

private AkavacheBlackList(IBlobCache blobcache)
{
private readonly IBlobCache _blackList;
private static TimeSpan? _defaultTtl;
this._blackList = blobcache;
}

private AkavacheBlackList(IBlobCache blobcache)
public async Task<bool> Delete(string key)
{
try
{
this._blackList = blobcache;
}
await this._blackList.Invalidate(key);

public static async Task<IBlackList> CreateStoreAsync(string cacheName, IBlobCache blobCache,
TimeSpan? defaultTtl = null)
return true;
}
catch
{
_defaultTtl = defaultTtl;
Registrations.Start(cacheName);
await blobCache.Vacuum();
return new AkavacheBlackList(blobCache);
return false;
}
}

public async Task DeleteAll()
{
await this._blackList.InvalidateAll();
}

public async Task<bool> Delete(string key)
public async Task<bool> IsRevoked(string key)
{
try
{
try
{
await _blackList.Invalidate(key);
return true;
}
catch
{
return false;
}
}
await this._blackList.Vacuum();
var exist = await this._blackList.Get(key);

public async Task DeleteAll()
return exist.Length > 0;
}
catch
{
await _blackList.InvalidateAll();
return false;
}
}

public async Task<bool> IsRevoked(string key)
public async Task<bool> Revoke(string key)
{
try
{
try
{
await _blackList.Vacuum();
var exist = await _blackList.Get(key);
return exist.Length > 0;
}
catch
{
return false;
}
}
await this._blackList.InsertObject(key, key, DateTimeOffset.Now.Add(_defaultTtl ?? TimeSpan.MaxValue));

public async Task<bool> Revoke(string key)
return true;
}
catch
{
try
{
await _blackList.InsertObject(key, key, DateTimeOffset.Now.Add(_defaultTtl ?? TimeSpan.MaxValue));
return true;
}
catch
{
return false;
}
return false;
}
}

public async Task<bool> Revoke(string key, TimeSpan expireAfter)
{
try
{
await this._blackList.InsertObject(key, key, DateTimeOffset.Now.Add(expireAfter));

public async Task<bool> Revoke(string key, TimeSpan expireAfter)
return true;
}
catch
{
try
{
await _blackList.InsertObject(key, key, DateTimeOffset.Now.Add(expireAfter));

return true;
}
catch
{
return false;
}
return false;
}
}

public async Task<bool> Revoke(string key, DateTime expireOn)
public async Task<bool> Revoke(string key, DateTime expireOn)
{
try
{
try
{
await _blackList.InsertObject(key, key, expireOn);

return true;
}
catch
{
return false;
}
await this._blackList.InsertObject(key, key, expireOn);

return true;
}
catch
{
return false;
}
}

public static async Task<IBlackList> CreateStoreAsync(string cacheName, IBlobCache blobCache, TimeSpan? defaultTtl = null)
{
_defaultTtl = defaultTtl;
Registrations.Start(cacheName);
await blobCache.Vacuum();

return new AkavacheBlackList(blobCache);
}
}
6 changes: 6 additions & 0 deletions Revoke.NET.Akavache/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Revoke.NET Akavache Store

Akavache BlackList Store Extension for [`Revoke.NET`] (https://www.nuget.org/packages/Revoke.NET)

# Installation

Install the `Revoke.NET.Akavache` [NuGet package](https://www.nuget.org/packages/Revoke.NET.Akavache) into your app

```powershell
PM> Install-Package Revoke.NET.Akavache
```

# How to use

```csharp
using Revoke.NET;
using Revoke.NET.Akavache;
Expand All @@ -27,7 +31,9 @@ await store.Delete(key); // Delete a key from blacklist
```

# Usage with ASP.NET Core

Install the `Revoke.NET.AspNetCore` [NuGet package](https://www.nuget.org/packages/Revoke.NET.AspNetCore)

```powershell
PM> Install-Package Revoke.NET.AspNetCore
```
Expand Down
70 changes: 35 additions & 35 deletions Revoke.NET.Akavache/Revoke.NET.Akavache.csproj
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<PackageIcon>revoke.net.png</PackageIcon>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>2.0.0</Version>
<StartupObject />
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET Akavache Store Extension</Description>
<Copyright>© 2022 Chakhoum Ahmed</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/rainxh11/Revoke.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/rainxh11/Revoke.NET/tree/main/Revoke.NET.Akavache</RepositoryUrl>
<RepositoryType>github</RepositoryType>
<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>
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<PackageIcon>revoke.net.png</PackageIcon>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<OutputType>Library</OutputType>
<Version>2.0.0</Version>
<StartupObject/>
<Authors>Chakhoum Ahmed (github.com/rainxh11)</Authors>
<Description>Revoke.NET Akavache Store Extension</Description>
<Copyright>© 2022 Chakhoum Ahmed</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/rainxh11/Revoke.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/rainxh11/Revoke.NET/tree/main/Revoke.NET.Akavache</RepositoryUrl>
<RepositoryType>github</RepositoryType>
<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>
<None Include="..\assets\revoke.net.png" Pack="true" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="..\LICENSE" Pack="true" PackagePath="\" />
<PackageReference Include="akavache" Version="9.0.1" />
<PackageReference Include="akavache.sqlite3" Version="9.0.1" />
<PackageReference Include="Revoke.NET" Version="2.0.1" />
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
<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="akavache" Version="9.0.1"/>
<PackageReference Include="akavache.sqlite3" Version="9.0.1"/>
<PackageReference Include="Revoke.NET" Version="2.0.1"/>
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/>
</ItemGroup>
</Target>
</Project>
55 changes: 24 additions & 31 deletions Revoke.NET.Akavache/RevokeService.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Revoke.NET.Akavache;

using System;
using global::Akavache;
using Microsoft.Extensions.DependencyInjection;
using Akavache;

namespace Revoke.NET.Akavache
public static class RevokeService
{
public static class RevokeService
public static IServiceCollection AddRevokeAkavacheSQLiteStore(this IServiceCollection services)
{
public static IServiceCollection AddRevokeAkavacheSQLiteStore(this IServiceCollection services)
{
return services
.AddSingleton<IBlackList>(provider => AkavacheBlackList
.CreateStoreAsync("RevokeStore", BlobCache.LocalMachine)
.GetAwaiter()
.GetResult());
}
return services.AddSingleton(
_ => AkavacheBlackList.CreateStoreAsync("RevokeStore", BlobCache.LocalMachine)
.GetAwaiter()
.GetResult());
}

public static IServiceCollection AddRevokeAkavacheInMemoryStore(this IServiceCollection services)
{
return services
.AddSingleton<IBlackList>(provider => AkavacheBlackList
.CreateStoreAsync("RevokeStore", BlobCache.InMemory)
.GetAwaiter()
.GetResult());
}
public static IServiceCollection AddRevokeAkavacheInMemoryStore(this IServiceCollection services)
{
return services.AddSingleton(
_ => AkavacheBlackList.CreateStoreAsync("RevokeStore", BlobCache.InMemory)
.GetAwaiter()
.GetResult());
}

public static IServiceCollection AddRevokeAkavacheStore(this IServiceCollection services,
Func<IServiceProvider, IBlobCache> configBlobCache)
{
return services
.AddSingleton<IBlackList>(provider => AkavacheBlackList
.CreateStoreAsync("RevokeStore", configBlobCache(provider))
.GetAwaiter()
.GetResult());
}
public static IServiceCollection AddRevokeAkavacheStore(this IServiceCollection services, Func<IServiceProvider, IBlobCache> configBlobCache)
{
return services.AddSingleton(
provider => AkavacheBlackList.CreateStoreAsync("RevokeStore", configBlobCache(provider))
.GetAwaiter()
.GetResult());
}
}
5 changes: 5 additions & 0 deletions Revoke.NET.AspNetCore/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Revoke.NET ASP.NET Core Extension

MongoDB BlackList Store Extension for [`Revoke.NET`] (https://www.nuget.org/packages/Revoke.NET)

# Installation

Install the `Revoke.NET.AspNetCore` [NuGet package](https://www.nuget.org/packages/Revoke.NET.AspNetCore) into your app

```powershell
PM> Install-Package Revoke.NET.AspNetCore
```

# Usage with ASP.NET Core

```csharp
using Revoke.NET;
using Revoke.NET.AspNetCore;
Expand All @@ -23,6 +27,7 @@ builder.Services
```

### JWT Bearer Token Example

```csharp
using System.Net.Http.Headers;
using Microsoft.AspNetCore.Mvc;
Expand Down
Loading

0 comments on commit bf17c1e

Please sign in to comment.