-
Notifications
You must be signed in to change notification settings - Fork 9.9k
/
TwitterPostConfigureOptions.cs
56 lines (48 loc) · 2.21 KB
/
TwitterPostConfigureOptions.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Net.Http;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Authentication.Twitter;
/// <summary>
/// Used to setup defaults for all <see cref="TwitterOptions"/>.
/// </summary>
public class TwitterPostConfigureOptions : IPostConfigureOptions<TwitterOptions>
{
private readonly IDataProtectionProvider _dp;
/// <summary>
/// Initializes the <see cref="TwitterPostConfigureOptions"/>.
/// </summary>
/// <param name="dataProtection">The <see cref="IDataProtectionProvider"/>.</param>
public TwitterPostConfigureOptions(IDataProtectionProvider dataProtection)
{
_dp = dataProtection;
}
/// <summary>
/// Invoked to post configure a TOptions instance.
/// </summary>
/// <param name="name">The name of the options instance being configured.</param>
/// <param name="options">The options instance to configure.</param>
public void PostConfigure(string? name, TwitterOptions options)
{
ArgumentNullException.ThrowIfNull(name);
options.DataProtectionProvider = options.DataProtectionProvider ?? _dp;
if (options.StateDataFormat == null)
{
var dataProtector = options.DataProtectionProvider.CreateProtector(
typeof(TwitterHandler).FullName!, name, "v1");
options.StateDataFormat = new SecureDataFormat<RequestToken>(
new RequestTokenSerializer(),
dataProtector);
}
if (options.Backchannel == null)
{
options.Backchannel = new HttpClient(options.BackchannelHttpHandler ?? new HttpClientHandler());
options.Backchannel.Timeout = options.BackchannelTimeout;
options.Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB
options.Backchannel.DefaultRequestHeaders.Accept.ParseAdd("*/*");
options.Backchannel.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft ASP.NET Core Twitter handler");
options.Backchannel.DefaultRequestHeaders.ExpectContinue = false;
}
}
}