Repository navigation
Expand file tree
/
Copy pathOAuthPostConfigureOptions.cs
More file actions
45 lines (40 loc) · 1.8 KB
/
Copy pathOAuthPostConfigureOptions.cs
File metadata and controls
45 lines (40 loc) · 1.8 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
// 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.Net.Http;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Options;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Used to setup defaults for the OAuthOptions.
/// </summary>
public class OAuthPostConfigureOptions<TOptions, THandler> : IPostConfigureOptions<TOptions>
where TOptions : OAuthOptions, new()
where THandler : OAuthHandler<TOptions>
{
private readonly IDataProtectionProvider _dp;
public OAuthPostConfigureOptions(IDataProtectionProvider dataProtection)
{
_dp = dataProtection;
}
public void PostConfigure(string name, TOptions options)
{
options.DataProtectionProvider = options.DataProtectionProvider ?? _dp;
if (options.Backchannel == null)
{
options.Backchannel = new HttpClient(options.BackchannelHttpHandler ?? new HttpClientHandler());
options.Backchannel.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft ASP.NET Core OAuth handler");
options.Backchannel.Timeout = options.BackchannelTimeout;
options.Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB
}
if (options.StateDataFormat == null)
{
var dataProtector = options.DataProtectionProvider.CreateProtector(
typeof(THandler).FullName, name, "v1");
options.StateDataFormat = new PropertiesDataFormat(dataProtector);
}
}
}
}