mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-22 07:42:28 +00:00
New: Use instance name in forms authentication cookie name
(cherry picked from commit 97ebaf279650082c6baee9563ef179921c5ed25a) Closes #5102
This commit is contained in:
parent
60fe75877b
commit
2818f4e073
1 changed files with 16 additions and 7 deletions
|
@ -1,7 +1,10 @@
|
|||
using System;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NzbDrone.Core.Authentication;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace Lidarr.Http.Authentication
|
||||
{
|
||||
|
@ -29,19 +32,25 @@ public static AuthenticationBuilder AddExternal(this AuthenticationBuilder authe
|
|||
|
||||
public static AuthenticationBuilder AddAppAuthentication(this IServiceCollection services)
|
||||
{
|
||||
return services.AddAuthentication()
|
||||
.AddNone(AuthenticationType.None.ToString())
|
||||
.AddExternal(AuthenticationType.External.ToString())
|
||||
.AddBasic(AuthenticationType.Basic.ToString())
|
||||
.AddCookie(AuthenticationType.Forms.ToString(), options =>
|
||||
services.AddOptions<CookieAuthenticationOptions>(AuthenticationType.Forms.ToString())
|
||||
.Configure<IConfigFileProvider>((options, configFileProvider) =>
|
||||
{
|
||||
options.Cookie.Name = "LidarrAuth";
|
||||
// Url Encode the cookie name to account for spaces or other invalid characters in the configured instance name
|
||||
var instanceName = HttpUtility.UrlEncode(configFileProvider.InstanceName);
|
||||
|
||||
options.Cookie.Name = $"{instanceName}Auth";
|
||||
options.AccessDeniedPath = "/login?loginFailed=true";
|
||||
options.LoginPath = "/login";
|
||||
options.ExpireTimeSpan = TimeSpan.FromDays(7);
|
||||
options.SlidingExpiration = true;
|
||||
options.ReturnUrlParameter = "returnUrl";
|
||||
})
|
||||
});
|
||||
|
||||
return services.AddAuthentication()
|
||||
.AddNone(AuthenticationType.None.ToString())
|
||||
.AddExternal(AuthenticationType.External.ToString())
|
||||
.AddBasic(AuthenticationType.Basic.ToString())
|
||||
.AddCookie(AuthenticationType.Forms.ToString())
|
||||
.AddApiKey("API", options =>
|
||||
{
|
||||
options.HeaderName = "X-Api-Key";
|
||||
|
|
Loading…
Reference in a new issue