summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth/OAuth/ServiceProviderDescription.cs
blob: 6205f559f25c0560c4020d2b78bedc5f7ce89ff5 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//-----------------------------------------------------------------------
// <copyright file="ServiceProviderDescription.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.OAuth {
	using System;
	using System.Diagnostics;
	using System.Diagnostics.CodeAnalysis;
	using System.Diagnostics.Contracts;
	using System.Linq;
	using DotNetOpenAuth.Messaging;
	using DotNetOpenAuth.OAuth.ChannelElements;

	/// <summary>
	/// A description of the endpoints on a Service Provider.
	/// </summary>
	public class ServiceProviderDescription {
		/// <summary>
		/// The field used to store the value of the <see cref="RequestTokenEndpoint"/> property.
		/// </summary>
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private MessageReceivingEndpoint requestTokenEndpoint;

		/// <summary>
		/// Initializes a new instance of the <see cref="ServiceProviderDescription"/> class.
		/// </summary>
		public ServiceProviderDescription() {
			this.ProtocolVersion = Protocol.Default.ProtocolVersion;
		}

		/// <summary>
		/// Gets or sets the OAuth version supported by the Service Provider.
		/// </summary>
		public ProtocolVersion ProtocolVersion { get; set; }

		/// <summary>
		/// Gets or sets the URL used to obtain an unauthorized Request Token,
		/// described in Section 6.1 (Obtaining an Unauthorized Request Token).
		/// </summary>
		/// <remarks>
		/// The request URL query MUST NOT contain any OAuth Protocol Parameters.
		/// This is the URL that <see cref="OAuth.Messages.UnauthorizedTokenRequest"/> messages are directed to.
		/// </remarks>
		/// <exception cref="ArgumentException">Thrown if this property is set to a URI with OAuth protocol parameters.</exception>
		public MessageReceivingEndpoint RequestTokenEndpoint {
			get {
				return this.requestTokenEndpoint;
			}

			set {
				if (value != null && UriUtil.QueryStringContainPrefixedParameters(value.Location, OAuth.Protocol.ParameterPrefix)) {
					throw new ArgumentException(OAuthStrings.RequestUrlMustNotHaveOAuthParameters);
				}

				this.requestTokenEndpoint = value;
			}
		}

		/// <summary>
		/// Gets or sets the URL used to obtain User authorization for Consumer access, 
		/// described in Section 6.2 (Obtaining User Authorization).
		/// </summary>
		/// <remarks>
		/// This is the URL that <see cref="OAuth.Messages.UserAuthorizationRequest"/> messages are
		/// indirectly (via the user agent) sent to.
		/// </remarks>
		public MessageReceivingEndpoint UserAuthorizationEndpoint { get; set; }

		/// <summary>
		/// Gets or sets the URL used to exchange the User-authorized Request Token 
		/// for an Access Token, described in Section 6.3 (Obtaining an Access Token).
		/// </summary>
		/// <remarks>
		/// This is the URL that <see cref="OAuth.Messages.AuthorizedTokenRequest"/> messages are directed to.
		/// </remarks>
		public MessageReceivingEndpoint AccessTokenEndpoint { get; set; }

		/// <summary>
		/// Gets or sets the signing policies that apply to this Service Provider.
		/// </summary>
		[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Type initializers require this format.")]
		public ITamperProtectionChannelBindingElement[] TamperProtectionElements { get; set; }

		/// <summary>
		/// Gets the OAuth version supported by the Service Provider.
		/// </summary>
		internal Version Version {
			get { return Protocol.Lookup(this.ProtocolVersion).Version; }
		}

		/// <summary>
		/// Creates a signing element that includes all the signing elements this service provider supports.
		/// </summary>
		/// <returns>The created signing element.</returns>
		internal ITamperProtectionChannelBindingElement CreateTamperProtectionElement() {
			Contract.Requires(this.TamperProtectionElements != null);
			return new SigningBindingElementChain(this.TamperProtectionElements.Select(el => (ITamperProtectionChannelBindingElement)el.Clone()).ToArray());
		}
	}
}