// 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
{
///
/// Used to setup defaults for all .
///
public class TwitterPostConfigureOptions : IPostConfigureOptions
{
private readonly IDataProtectionProvider _dp;
public TwitterPostConfigureOptions(IDataProtectionProvider dataProtection)
{
_dp = dataProtection;
}
///
/// Invoked to post configure a TOptions instance.
///
/// The name of the options instance being configured.
/// The options instance to configure.
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(
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;
}
}
}
}