add support for named site options
This commit is contained in:
@ -28,7 +28,7 @@ namespace Oqtane.Extensions
|
|||||||
public static OqtaneSiteOptionsBuilder WithSiteAuthentication(this OqtaneSiteOptionsBuilder builder)
|
public static OqtaneSiteOptionsBuilder WithSiteAuthentication(this OqtaneSiteOptionsBuilder builder)
|
||||||
{
|
{
|
||||||
// site cookie authentication options
|
// site cookie authentication options
|
||||||
builder.AddSiteOptions<CookieAuthenticationOptions>((options, alias, sitesettings) =>
|
builder.AddSiteNamedOptions<CookieAuthenticationOptions>(Constants.AuthenticationScheme, (options, alias, sitesettings) =>
|
||||||
{
|
{
|
||||||
options.Cookie.Name = sitesettings.GetValue("LoginOptions:CookieName", ".AspNetCore.Identity.Application");
|
options.Cookie.Name = sitesettings.GetValue("LoginOptions:CookieName", ".AspNetCore.Identity.Application");
|
||||||
});
|
});
|
||||||
|
@ -17,10 +17,22 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
}
|
}
|
||||||
|
|
||||||
public OqtaneSiteOptionsBuilder AddSiteOptions<TOptions>(
|
public OqtaneSiteOptionsBuilder AddSiteOptions<TOptions>(
|
||||||
Action<TOptions, Alias, Dictionary<string, string>> action) where TOptions : class, new()
|
Action<TOptions, Alias, Dictionary<string, string>> configureOptions) where TOptions : class, new()
|
||||||
{
|
{
|
||||||
Services.TryAddSingleton<IOptionsMonitorCache<TOptions>, SiteOptionsCache<TOptions>>();
|
Services.TryAddSingleton<IOptionsMonitorCache<TOptions>, SiteOptionsCache<TOptions>>();
|
||||||
Services.AddSingleton<ISiteOptions<TOptions>, SiteOptions<TOptions>> (sp => new SiteOptions<TOptions>(action));
|
Services.AddSingleton<ISiteOptions<TOptions>, SiteOptions<TOptions>> (_ => new SiteOptions<TOptions>(configureOptions));
|
||||||
|
Services.TryAddTransient<IOptionsFactory<TOptions>, SiteOptionsFactory<TOptions>>();
|
||||||
|
Services.TryAddScoped<IOptionsSnapshot<TOptions>>(sp => BuildOptionsManager<TOptions>(sp));
|
||||||
|
Services.TryAddSingleton<IOptions<TOptions>>(sp => BuildOptionsManager<TOptions>(sp));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OqtaneSiteOptionsBuilder AddSiteNamedOptions<TOptions>(string name,
|
||||||
|
Action<TOptions, Alias, Dictionary<string, string>> configureOptions) where TOptions : class, new()
|
||||||
|
{
|
||||||
|
Services.TryAddSingleton<IOptionsMonitorCache<TOptions>, SiteOptionsCache<TOptions>>();
|
||||||
|
Services.AddSingleton<ISiteNamedOptions<TOptions>, SiteNamedOptions<TOptions>>(_ => new SiteNamedOptions<TOptions>(name, configureOptions));
|
||||||
Services.TryAddTransient<IOptionsFactory<TOptions>, SiteOptionsFactory<TOptions>>();
|
Services.TryAddTransient<IOptionsFactory<TOptions>, SiteOptionsFactory<TOptions>>();
|
||||||
Services.TryAddScoped<IOptionsSnapshot<TOptions>>(sp => BuildOptionsManager<TOptions>(sp));
|
Services.TryAddScoped<IOptionsSnapshot<TOptions>>(sp => BuildOptionsManager<TOptions>(sp));
|
||||||
Services.TryAddSingleton<IOptions<TOptions>>(sp => BuildOptionsManager<TOptions>(sp));
|
Services.TryAddSingleton<IOptions<TOptions>>(sp => BuildOptionsManager<TOptions>(sp));
|
||||||
|
11
Oqtane.Server/Infrastructure/Options/ISiteNamedOptions.cs
Normal file
11
Oqtane.Server/Infrastructure/Options/ISiteNamedOptions.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace Oqtane.Infrastructure
|
||||||
|
{
|
||||||
|
public interface ISiteNamedOptions<TOptions>
|
||||||
|
where TOptions : class, new()
|
||||||
|
{
|
||||||
|
void Configure(string name, TOptions options, Alias alias, Dictionary<string, string> sitesettings);
|
||||||
|
}
|
||||||
|
}
|
28
Oqtane.Server/Infrastructure/Options/SiteNamedOptions.cs
Normal file
28
Oqtane.Server/Infrastructure/Options/SiteNamedOptions.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
|
namespace Oqtane.Infrastructure
|
||||||
|
{
|
||||||
|
public class SiteNamedOptions<TOptions> : ISiteNamedOptions<TOptions>
|
||||||
|
where TOptions : class, new()
|
||||||
|
{
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
private readonly Action<TOptions, Alias, Dictionary<string, string>> configureOptions;
|
||||||
|
|
||||||
|
public SiteNamedOptions(string name, Action<TOptions, Alias, Dictionary<string, string>> configureOptions)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
this.configureOptions = configureOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Configure(string name, TOptions options, Alias alias, Dictionary<string, string> sitesettings)
|
||||||
|
{
|
||||||
|
if (name == Name)
|
||||||
|
{
|
||||||
|
configureOptions(options, alias, sitesettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -114,12 +114,12 @@ namespace Oqtane
|
|||||||
services.ConfigureOqtaneIdentityOptions(Configuration);
|
services.ConfigureOqtaneIdentityOptions(Configuration);
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.DefaultScheme = Constants.AuthenticationScheme;
|
options.DefaultScheme = Constants.AuthenticationScheme;
|
||||||
})
|
})
|
||||||
.AddCookie(Constants.AuthenticationScheme)
|
.AddCookie(Constants.AuthenticationScheme)
|
||||||
.AddOpenIdConnect(AuthenticationProviderTypes.OpenIDConnect, options => { })
|
.AddOpenIdConnect(AuthenticationProviderTypes.OpenIDConnect, options => { })
|
||||||
.AddOAuth(AuthenticationProviderTypes.OAuth2, options => { });
|
.AddOAuth(AuthenticationProviderTypes.OAuth2, options => { });
|
||||||
|
|
||||||
services.ConfigureOqtaneCookieOptions();
|
services.ConfigureOqtaneCookieOptions();
|
||||||
services.ConfigureOqtaneAuthenticationOptions(Configuration);
|
services.ConfigureOqtaneAuthenticationOptions(Configuration);
|
||||||
|
Reference in New Issue
Block a user