summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2.AuthorizationServer/Configuration/OAuth2AuthorizationServerSection.cs
blob: a06555d583efdfadcaf31253b379b09598d4be6d (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
60
61
62
63
64
65
66
67
68
//-----------------------------------------------------------------------
// <copyright file="OAuth2AuthorizationServerSection.cs" company="Outercurve Foundation">
//     Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.Configuration {
	using System;
	using System.Configuration;
	using DotNetOpenAuth.Messaging.Bindings;
	using DotNetOpenAuth.OAuth2.ChannelElements;

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

		/// <summary>
		/// The name of the &lt;clientAuthenticationModules&gt; sub-element.
		/// </summary>
		private const string ClientAuthenticationModulesElementName = "clientAuthenticationModules";

		/// <summary>
		/// The built-in set of client authentication modules.
		/// </summary>
		private static readonly TypeConfigurationCollection<ClientAuthenticationModule> defaultClientAuthenticationModules =
			new TypeConfigurationCollection<ClientAuthenticationModule>(new Type[] { typeof(ClientCredentialHttpBasicReader), typeof(ClientCredentialMessagePartReader) });

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

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

		/// <summary>
		/// Gets or sets the services to use for discovering service endpoints for identifiers.
		/// </summary>
		/// <remarks>
		/// If no discovery services are defined in the (web) application's .config file,
		/// the default set of discovery services built into the library are used.
		/// </remarks>
		[ConfigurationProperty(ClientAuthenticationModulesElementName, IsDefaultCollection = false)]
		[ConfigurationCollection(typeof(TypeConfigurationCollection<ClientAuthenticationModule>))]
		internal TypeConfigurationCollection<ClientAuthenticationModule> ClientAuthenticationModules {
			get {
				var configResult = (TypeConfigurationCollection<ClientAuthenticationModule>)this[ClientAuthenticationModulesElementName];
				return configResult != null && configResult.Count > 0 ? configResult : defaultClientAuthenticationModules;
			}

			set {
				this[ClientAuthenticationModulesElementName] = value;
			}
		}
	}
}