Repository navigation
Expand file tree
/
Copy pathCookieServiceCollectionExtensions.cs
More file actions
57 lines (50 loc) · 2.43 KB
/
Copy pathCookieServiceCollectionExtensions.cs
File metadata and controls
57 lines (50 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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.Cookies;
using Microsoft.Extensions.Configuration;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for setting up cookie authentication services in an <see cref="IServiceCollection" />.
/// </summary>
public static class CookieServiceCollectionExtensions
{
/// <summary>
/// Adds cookie authentication services to the specified <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
/// <param name="configure">An action delegate to configure the provided <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}
return services.Configure(configure);
}
/// <summary>
/// Adds cookie authentication services to the specified <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
/// <param name="config">An <see cref="IConfiguration"/> instance that contains configuration data representing a <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddCookieAuthentication(this IServiceCollection services, IConfiguration config)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
return services.Configure<CookieAuthenticationOptions>(config);
}
}
}