54 lines
2.2 KiB
C#
54 lines
2.2 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using Microsoft.AspNet.Authentication;
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for setting up authentication services in an <see cref="IServiceCollection" />.
|
|
/// </summary>
|
|
public static class AuthenticationServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds authentication services to the specified <see cref="IServiceCollection" />.
|
|
/// </summary>
|
|
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
|
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
public static IServiceCollection AddAuthentication(this IServiceCollection services)
|
|
{
|
|
if (services == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(services));
|
|
}
|
|
|
|
services.AddWebEncoders();
|
|
services.AddDataProtection();
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds authentication services to the specified <see cref="IServiceCollection" />.
|
|
/// </summary>
|
|
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
|
|
/// <param name="configureOptions">An action delegate to configure the provided <see cref="SharedAuthenticationOptions"/>.</param>
|
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
|
public static IServiceCollection AddAuthentication(this IServiceCollection services, Action<SharedAuthenticationOptions> configureOptions)
|
|
{
|
|
if (services == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(services));
|
|
}
|
|
|
|
if (configureOptions == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(configureOptions));
|
|
}
|
|
|
|
services.Configure(configureOptions);
|
|
return services.AddAuthentication();
|
|
}
|
|
}
|
|
}
|