//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Configuration { using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using DotNetOpenAuth.OAuth; /// /// Security settings that are applicable to service providers. /// internal class OAuthServiceProviderSecuritySettingsElement : ConfigurationElement { /// /// Gets the name of the @minimumRequiredOAuthVersion attribute. /// private const string MinimumRequiredOAuthVersionConfigName = "minimumRequiredOAuthVersion"; /// /// Gets the name of the @maxAuthorizationTime attribute. /// private const string MaximumRequestTokenTimeToLiveConfigName = "maxAuthorizationTime"; /// /// Initializes a new instance of the class. /// internal OAuthServiceProviderSecuritySettingsElement() { } /// /// Gets or sets the minimum OAuth version a Consumer is required to support in order for this library to interoperate with it. /// /// /// Although the earliest versions of OAuth are supported, for security reasons it may be desirable to require the /// remote party to support a later version of OAuth. /// [ConfigurationProperty(MinimumRequiredOAuthVersionConfigName, DefaultValue = "V10")] public ProtocolVersion MinimumRequiredOAuthVersion { get { return (ProtocolVersion)this[MinimumRequiredOAuthVersionConfigName]; } set { this[MinimumRequiredOAuthVersionConfigName] = value; } } /// /// Gets or sets the maximum time a user can take to complete authorization. /// /// /// This time limit serves as a security mitigation against brute force attacks to /// compromise (unauthorized or authorized) request tokens. /// Longer time limits is more friendly to slow users or consumers, while shorter /// time limits provide better security. /// [ConfigurationProperty(MaximumRequestTokenTimeToLiveConfigName, DefaultValue = "0:05")] // 5 minutes [PositiveTimeSpanValidator] public TimeSpan MaximumRequestTokenTimeToLive { get { return (TimeSpan)this[MaximumRequestTokenTimeToLiveConfigName]; } set { this[MaximumRequestTokenTimeToLiveConfigName] = value; } } /// /// Initializes a programmatically manipulatable bag of these security settings with the settings from the config file. /// /// The newly created security settings object. internal ServiceProviderSecuritySettings CreateSecuritySettings() { return new ServiceProviderSecuritySettings { MinimumRequiredOAuthVersion = this.MinimumRequiredOAuthVersion, MaximumRequestTokenTimeToLive = this.MaximumRequestTokenTimeToLive, }; } } }