You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
2.1 KiB
51 lines
2.1 KiB
using System;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NzbDrone.Core.Authentication;
|
|
|
|
namespace Lidarr.Http.Authentication
|
|
{
|
|
public static class AuthenticationBuilderExtensions
|
|
{
|
|
public static AuthenticationBuilder AddApiKey(this AuthenticationBuilder authenticationBuilder, string name, Action<ApiKeyAuthenticationOptions> options)
|
|
{
|
|
return authenticationBuilder.AddScheme<ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(name, options);
|
|
}
|
|
|
|
public static AuthenticationBuilder AddBasic(this AuthenticationBuilder authenticationBuilder, string name)
|
|
{
|
|
return authenticationBuilder.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>(name, options => { });
|
|
}
|
|
|
|
public static AuthenticationBuilder AddNone(this AuthenticationBuilder authenticationBuilder, string name)
|
|
{
|
|
return authenticationBuilder.AddScheme<AuthenticationSchemeOptions, NoAuthenticationHandler>(name, options => { });
|
|
}
|
|
|
|
public static AuthenticationBuilder AddAppAuthentication(this IServiceCollection services)
|
|
{
|
|
return services.AddAuthentication()
|
|
.AddNone(AuthenticationType.None.ToString())
|
|
.AddBasic(AuthenticationType.Basic.ToString())
|
|
.AddCookie(AuthenticationType.Forms.ToString(), options =>
|
|
{
|
|
options.Cookie.Name = "LidarrAuth";
|
|
options.AccessDeniedPath = "/login?loginFailed=true";
|
|
options.LoginPath = "/login";
|
|
options.ExpireTimeSpan = TimeSpan.FromDays(7);
|
|
options.SlidingExpiration = true;
|
|
})
|
|
.AddApiKey("API", options =>
|
|
{
|
|
options.HeaderName = "X-Api-Key";
|
|
options.QueryName = "apikey";
|
|
})
|
|
.AddApiKey("SignalR", options =>
|
|
{
|
|
options.HeaderName = "X-Api-Key";
|
|
options.QueryName = "access_token";
|
|
});
|
|
}
|
|
}
|
|
}
|