mirror of
https://github.com/Radarr/Radarr
synced 2025-12-09 09:56:04 +01:00
(cherry picked from commit d6170dbfedf27a6218afe242a0fae2eb8b368aec) (cherry picked from commit 7fe36a7e9222e830f4920e09a85115df0bdbf190)
48 lines
2 KiB
C#
48 lines
2 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NzbDrone.Core.Authentication;
|
|
|
|
namespace Radarr.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.AccessDeniedPath = "/login?loginFailed=true";
|
|
options.LoginPath = "/login";
|
|
options.ExpireTimeSpan = TimeSpan.FromDays(7);
|
|
})
|
|
.AddApiKey("API", options =>
|
|
{
|
|
options.HeaderName = "X-Api-Key";
|
|
options.QueryName = "apikey";
|
|
})
|
|
.AddApiKey("SignalR", options =>
|
|
{
|
|
options.HeaderName = "X-Api-Key";
|
|
options.QueryName = "access_token";
|
|
});
|
|
}
|
|
}
|
|
}
|