summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2.Client/Configuration/OAuth2ClientSection.cs
blob: d0c27c94704dfc9a744212d7db2ae6cc60045019 (plain)
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
57
58
59
//-----------------------------------------------------------------------
// <copyright file="OAuth2ClientSection.cs" company="Outercurve Foundation">
//     Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Configuration {
	using System;
	using System.Configuration;
	using Validation;

	/// <summary>
	/// Represents the &lt;oauth2/client&gt; section in the host's .config file.
	/// </summary>
	internal class OAuth2ClientSection : ConfigurationSection {
		/// <summary>
		/// The name of the oauth2/client section.
		/// </summary>
		private const string SectionName = OAuth2SectionGroup.SectionName + "/client";

		/// <summary>
		/// The name of the @maxAuthorizationTime attribute.
		/// </summary>
		private const string MaxAuthorizationTimePropertyName = "maxAuthorizationTime";

		/// <summary>
		/// Initializes a new instance of the <see cref="OAuth2ClientSection"/> class.
		/// </summary>
		internal OAuth2ClientSection() {
		}

		/// <summary>
		/// Gets the configuration section from the .config file.
		/// </summary>
		internal static OAuth2ClientSection Configuration {
			get {
				return (OAuth2ClientSection)ConfigurationManager.GetSection(SectionName) ?? new OAuth2ClientSection();
			}
		}

		/// <summary>
		/// Gets or sets the maximum time a user can take to complete authentication.
		/// </summary>
		[ConfigurationProperty(MaxAuthorizationTimePropertyName, DefaultValue = "0:15")] // 15 minutes
		[PositiveTimeSpanValidator]
		internal TimeSpan MaxAuthorizationTime {
			get {
				TimeSpan result = (TimeSpan)this[MaxAuthorizationTimePropertyName];
				Assumes.True(result > TimeSpan.Zero); // our PositiveTimeSpanValidator should take care of this
				return result;
			}

			set {
				Requires.Range(value > TimeSpan.Zero, "value");
				this[MaxAuthorizationTimePropertyName] = value;
			}
		}
	}
}