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

26 lines
916 B
C#
Raw Normal View History

2020-12-21 22:58:40 +02:00
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;
}
}
}