netmash/NDB.Security.Authentication.../BasicAuthenticationExtensio...

26 lines
916 B
C#

using IdentityServer.Wrapper;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace NDB.Security.Authentication.Identity
{
public static class BasicAuthenticationExtensions
{
public static IServiceCollection AddBasicAuthentication(this IServiceCollection services, string identityServerBaseAddress)
{
if (string.IsNullOrEmpty(identityServerBaseAddress))
throw new Exception($"Identity server base address must be provided.");
// Identity server
services.UseIdentityServices(identityServerBaseAddress);
// configure basic authentication
services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
return services;
}
}
}