Skip to content

Commit

Permalink
Added DynamicAuthSchemeService
Browse files Browse the repository at this point in the history
  • Loading branch information
maximiliancsuk committed Aug 21, 2023
1 parent 62acb4e commit b92f319
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions backend/Omnikeeper/Service/DynamicAuthSchemeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Authentication;
using System.Threading.Tasks;

namespace Omnikeeper.Service
{
public class DynamicAuthSchemeService
{
private readonly IAuthenticationSchemeProvider schemeProvider;
//private readonly IOptionsMonitorCache<O> optionsCache;

public DynamicAuthSchemeService(IAuthenticationSchemeProvider schemeProvider)//, IOptionsMonitorCache<SimpleOptions> optionsCache)
{
this.schemeProvider = schemeProvider;
//this.optionsCache = optionsCache;
}

public async Task<bool> TryAdd(string scheme, System.Type handlerType)
{
if (await schemeProvider.GetSchemeAsync(scheme) == null)
{
schemeProvider.AddScheme(new AuthenticationScheme(scheme, scheme, handlerType));
return true;
}
else
{
return false;
}
//else
//{
// _optionsCache.TryRemove(scheme);
//}
//_optionsCache.TryAdd(scheme, new SimpleOptions { DisplayMessage = optionsMessage });
}
}
}
1 change: 1 addition & 0 deletions backend/Omnikeeper/Startup/ServiceRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public static void RegisterServices(ContainerBuilder builder)
builder.RegisterType<AuthzFilterManager>().As<IAuthzFilterManager>().SingleInstance();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AssignableTo<IAuthzFilterForMutation>().As<IAuthzFilterForMutation>().SingleInstance();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AssignableTo<IAuthzFilterForQuery>().As<IAuthzFilterForQuery>().SingleInstance();
builder.RegisterType<DynamicAuthSchemeService>().SingleInstance();

builder.RegisterType<ReactiveRunService>().As<IReactiveRunService>().SingleInstance();
}
Expand Down

0 comments on commit b92f319

Please sign in to comment.