-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
TwitterPostConfigureOptions.cs
51 lines (45 loc) · 2.15 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
// 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.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;
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)
{
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;
}
}
}
}