summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs30
-rw-r--r--src/DotNetOAuth.Test/DotNetOAuth.Test.csproj1
-rw-r--r--src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs12
-rw-r--r--src/DotNetOAuth.Test/Scenarios.cs30
-rw-r--r--src/DotNetOAuth.Test/ServiceProviderTests.cs40
-rw-r--r--src/DotNetOAuth/ChannelElements/IOAuthDirectedMessage.cs (renamed from src/DotNetOAuth/ChannelElements/IOAuthProtocolDirectedMessage.cs)6
-rw-r--r--src/DotNetOAuth/ChannelElements/OAuthChannel.cs38
-rw-r--r--src/DotNetOAuth/Consumer.cs30
-rw-r--r--src/DotNetOAuth/DotNetOAuth.csproj6
-rw-r--r--src/DotNetOAuth/Messages/AccessProtectedResourcesMessage.cs2
-rw-r--r--src/DotNetOAuth/Messages/DirectUserToConsumerMessage.cs2
-rw-r--r--src/DotNetOAuth/Messages/DirectUserToServiceProviderMessage.cs2
-rw-r--r--src/DotNetOAuth/Messages/MessageBase.cs19
-rw-r--r--src/DotNetOAuth/Messages/RequestAccessTokenMessage.cs2
-rw-r--r--src/DotNetOAuth/Messages/RequestTokenMessage.cs2
-rw-r--r--src/DotNetOAuth/Messages/SignedMessageBase.cs2
-rw-r--r--src/DotNetOAuth/Messaging/HttpDeliveryMethod.cs (renamed from src/DotNetOAuth/Messaging/MessageScheme.cs)22
-rw-r--r--src/DotNetOAuth/ServiceProvider.cs17
-rw-r--r--src/DotNetOAuth/ServiceProviderEndpoint.cs53
19 files changed, 233 insertions, 83 deletions
diff --git a/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs b/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs
index 9a98728..5917d2c 100644
--- a/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs
@@ -58,17 +58,17 @@ namespace DotNetOAuth.Test.ChannelElements {
[TestMethod]
public void ReadFromRequestAuthorization() {
- this.ParameterizedReceiveTest(MessageScheme.AuthorizationHeaderRequest);
+ this.ParameterizedReceiveTest(HttpDeliveryMethod.AuthorizationHeaderRequest);
}
[TestMethod]
public void ReadFromRequestForm() {
- this.ParameterizedReceiveTest(MessageScheme.PostRequest);
+ this.ParameterizedReceiveTest(HttpDeliveryMethod.PostRequest);
}
[TestMethod]
public void ReadFromRequestQueryString() {
- this.ParameterizedReceiveTest(MessageScheme.GetRequest);
+ this.ParameterizedReceiveTest(HttpDeliveryMethod.GetRequest);
}
[TestMethod]
@@ -135,23 +135,23 @@ namespace DotNetOAuth.Test.ChannelElements {
public void RequestBadPreferredScheme() {
TestDirectedMessage message = new TestDirectedMessage(MessageTransport.Direct);
message.Recipient = new Uri("http://localtest");
- this.channel.PreferredTransmissionScheme = (MessageScheme)100;
+ message.HttpMethods = HttpDeliveryMethod.None;
this.channel.Request(message);
}
[TestMethod]
public void RequestUsingAuthorizationHeader() {
- this.ParameterizedRequestTest(MessageScheme.AuthorizationHeaderRequest);
+ this.ParameterizedRequestTest(HttpDeliveryMethod.AuthorizationHeaderRequest);
}
[TestMethod]
public void RequestUsingGet() {
- this.ParameterizedRequestTest(MessageScheme.GetRequest);
+ this.ParameterizedRequestTest(HttpDeliveryMethod.GetRequest);
}
[TestMethod]
public void RequestUsingPost() {
- this.ParameterizedRequestTest(MessageScheme.PostRequest);
+ this.ParameterizedRequestTest(HttpDeliveryMethod.PostRequest);
}
private static string CreateAuthorizationHeader(IDictionary<string, string> fields) {
@@ -174,14 +174,14 @@ namespace DotNetOAuth.Test.ChannelElements {
return authorization.ToString();
}
- private static HttpRequestInfo CreateHttpRequestInfo(MessageScheme scheme, IDictionary<string, string> fields) {
+ private static HttpRequestInfo CreateHttpRequestInfo(HttpDeliveryMethod scheme, IDictionary<string, string> fields) {
string query = MessagingUtilities.CreateQueryString(fields);
UriBuilder requestUri = new UriBuilder("http://localhost/path");
WebHeaderCollection headers = new WebHeaderCollection();
MemoryStream ms = new MemoryStream();
string method;
switch (scheme) {
- case MessageScheme.PostRequest:
+ case HttpDeliveryMethod.PostRequest:
method = "POST";
headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
StreamWriter sw = new StreamWriter(ms);
@@ -189,11 +189,11 @@ namespace DotNetOAuth.Test.ChannelElements {
sw.Flush();
ms.Position = 0;
break;
- case MessageScheme.GetRequest:
+ case HttpDeliveryMethod.GetRequest:
method = "GET";
requestUri.Query = query;
break;
- case MessageScheme.AuthorizationHeaderRequest:
+ case HttpDeliveryMethod.AuthorizationHeaderRequest:
method = "GET";
headers.Add(HttpRequestHeader.Authorization, CreateAuthorizationHeader(fields));
break;
@@ -220,20 +220,21 @@ namespace DotNetOAuth.Test.ChannelElements {
return info;
}
- private void ParameterizedRequestTest(MessageScheme scheme) {
+ private void ParameterizedRequestTest(HttpDeliveryMethod scheme) {
TestDirectedMessage request = new TestDirectedMessage(MessageTransport.Direct) {
Age = 15,
Name = "Andrew",
Location = new Uri("http://hostb/pathB"),
Recipient = new Uri("http://localtest"),
Timestamp = DateTime.UtcNow,
+ HttpMethods = scheme,
};
Response rawResponse = null;
this.webRequestHandler.Callback = (req) => {
Assert.IsNotNull(req);
HttpRequestInfo reqInfo = ConvertToRequestInfo(req, this.webRequestHandler.RequestEntityStream);
- Assert.AreEqual(scheme == MessageScheme.PostRequest ? "POST" : "GET", reqInfo.HttpMethod);
+ Assert.AreEqual(scheme == HttpDeliveryMethod.PostRequest ? "POST" : "GET", reqInfo.HttpMethod);
var incomingMessage = this.channel.ReadFromRequest(reqInfo) as TestMessage;
Assert.IsNotNull(incomingMessage);
Assert.AreEqual(request.Age, incomingMessage.Age);
@@ -253,7 +254,6 @@ namespace DotNetOAuth.Test.ChannelElements {
return rawResponse;
};
- this.channel.PreferredTransmissionScheme = scheme;
IProtocolMessage response = this.channel.Request(request);
Assert.IsNotNull(response);
Assert.IsInstanceOfType(response, typeof(TestMessage));
@@ -263,7 +263,7 @@ namespace DotNetOAuth.Test.ChannelElements {
Assert.AreEqual(request.Location, responseMessage.Location);
}
- private void ParameterizedReceiveTest(MessageScheme scheme) {
+ private void ParameterizedReceiveTest(HttpDeliveryMethod scheme) {
var fields = new Dictionary<string, string> {
{ "age", "15" },
{ "Name", "Andrew" },
diff --git a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
index 63ad5a2..2859ffc 100644
--- a/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
+++ b/src/DotNetOAuth.Test/DotNetOAuth.Test.csproj
@@ -88,6 +88,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Messaging\ResponseTests.cs" />
<Compile Include="ProtocolTests.cs" />
+ <Compile Include="Scenarios.cs" />
<Compile Include="ServiceProviderTests.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="UriUtilTests.cs" />
diff --git a/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs b/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
index 6938ef5..719a4a9 100644
--- a/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
+++ b/src/DotNetOAuth.Test/Mocks/TestDirectedMessage.cs
@@ -6,12 +6,10 @@
namespace DotNetOAuth.Test.Mocks {
using System;
- using System.Collections.Generic;
- using System.Runtime.Serialization;
+ using DotNetOAuth.ChannelElements;
using DotNetOAuth.Messaging;
- using DotNetOAuth.Messaging.Reflection;
- internal class TestDirectedMessage : TestMessage, IDirectedProtocolMessage {
+ internal class TestDirectedMessage : TestMessage, IOAuthDirectedMessage {
internal TestDirectedMessage() {
}
@@ -32,6 +30,12 @@ namespace DotNetOAuth.Test.Mocks {
#endregion
+ #region IOAuthDirectedMessage Members
+
+ public HttpDeliveryMethod HttpMethods { get; internal set; }
+
+ #endregion
+
protected virtual MessageProtection RequiredProtection {
get { return MessageProtection.None; }
}
diff --git a/src/DotNetOAuth.Test/Scenarios.cs b/src/DotNetOAuth.Test/Scenarios.cs
new file mode 100644
index 0000000..6718b47
--- /dev/null
+++ b/src/DotNetOAuth.Test/Scenarios.cs
@@ -0,0 +1,30 @@
+//-----------------------------------------------------------------------
+// <copyright file="Scenarios.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Test {
+ using DotNetOAuth.Messaging;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+ [TestClass]
+ public class Scenarios : TestBase {
+ [TestMethod]
+ public void SpecAppendixAExample() {
+ ServiceProvider sp = new ServiceProvider {
+ RequestTokenEndpoint = new ServiceProviderEndpoint("https://photos.example.net/request_token", HttpDeliveryMethod.PostRequest),
+ UserAuthorizationEndpoint = new ServiceProviderEndpoint("http://photos.example.net/authorize", HttpDeliveryMethod.GetRequest),
+ AccessTokenEndpoint = new ServiceProviderEndpoint("https://photos.example.net/access_token", HttpDeliveryMethod.PostRequest),
+ };
+
+ Consumer consumer = new Consumer {
+ ConsumerKey = "dpf43f3p2l4k3l03",
+ ConsumerSecret = "kd94hf93k423kf44",
+ ServiceProvider = sp,
+ };
+
+ consumer.RequestUserAuthorization();
+ }
+ }
+}
diff --git a/src/DotNetOAuth.Test/ServiceProviderTests.cs b/src/DotNetOAuth.Test/ServiceProviderTests.cs
index 73663cf..001bacf 100644
--- a/src/DotNetOAuth.Test/ServiceProviderTests.cs
+++ b/src/DotNetOAuth.Test/ServiceProviderTests.cs
@@ -6,6 +6,7 @@
namespace DotNetOAuth.Test {
using System;
+ using DotNetOAuth.Messaging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
@@ -19,24 +20,30 @@ namespace DotNetOAuth.Test {
[TestMethod]
public void UserAuthorizationUriTest() {
ServiceProvider target = new ServiceProvider();
- Uri expected = new Uri("http://localhost/authorization");
- Uri actual;
- target.UserAuthorizationUri = expected;
- actual = target.UserAuthorizationUri;
+ ServiceProviderEndpoint expected = new ServiceProviderEndpoint("http://localhost/authorization", HttpDeliveryMethod.GetRequest);
+ ServiceProviderEndpoint actual;
+ target.UserAuthorizationEndpoint = expected;
+ actual = target.UserAuthorizationEndpoint;
Assert.AreEqual(expected, actual);
+
+ target.UserAuthorizationEndpoint = null;
+ Assert.IsNull(target.UserAuthorizationEndpoint);
}
/// <summary>
/// A test for RequestTokenUri
/// </summary>
- [TestMethod()]
+ [TestMethod]
public void RequestTokenUriTest() {
ServiceProvider target = new ServiceProvider();
- Uri expected = new Uri("http://localhost/requesttoken");
- Uri actual;
- target.RequestTokenUri = expected;
- actual = target.RequestTokenUri;
+ ServiceProviderEndpoint expected = new ServiceProviderEndpoint("http://localhost/requesttoken", HttpDeliveryMethod.GetRequest);
+ ServiceProviderEndpoint actual;
+ target.RequestTokenEndpoint = expected;
+ actual = target.RequestTokenEndpoint;
Assert.AreEqual(expected, actual);
+
+ target.RequestTokenEndpoint = null;
+ Assert.IsNull(target.RequestTokenEndpoint);
}
/// <summary>
@@ -46,20 +53,23 @@ namespace DotNetOAuth.Test {
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void RequestTokenUriWithOAuthParametersTest() {
ServiceProvider target = new ServiceProvider();
- target.RequestTokenUri = new Uri("http://localhost/requesttoken?oauth_token=something");
+ target.RequestTokenEndpoint = new ServiceProviderEndpoint("http://localhost/requesttoken?oauth_token=something", HttpDeliveryMethod.GetRequest);
}
/// <summary>
/// A test for AccessTokenUri
/// </summary>
- [TestMethod()]
+ [TestMethod]
public void AccessTokenUriTest() {
ServiceProvider target = new ServiceProvider();
- Uri expected = new Uri("http://localhost/accesstoken");
- Uri actual;
- target.AccessTokenUri = expected;
- actual = target.AccessTokenUri;
+ ServiceProviderEndpoint expected = new ServiceProviderEndpoint("http://localhost/accesstoken", HttpDeliveryMethod.GetRequest);
+ ServiceProviderEndpoint actual;
+ target.AccessTokenEndpoint = expected;
+ actual = target.AccessTokenEndpoint;
Assert.AreEqual(expected, actual);
+
+ target.AccessTokenEndpoint = null;
+ Assert.IsNull(target.AccessTokenEndpoint);
}
}
}
diff --git a/src/DotNetOAuth/ChannelElements/IOAuthProtocolDirectedMessage.cs b/src/DotNetOAuth/ChannelElements/IOAuthDirectedMessage.cs
index 6399c9c..9483005 100644
--- a/src/DotNetOAuth/ChannelElements/IOAuthProtocolDirectedMessage.cs
+++ b/src/DotNetOAuth/ChannelElements/IOAuthDirectedMessage.cs
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
-// <copyright file="IOAuthProtocolDirectedMessage.cs" company="Andrew Arnott">
+// <copyright file="IOAuthDirectedMessage.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
@@ -10,10 +10,10 @@ namespace DotNetOAuth.ChannelElements {
/// <summary>
/// Additional properties that apply specifically to OAuth messages.
/// </summary>
- internal interface IOAuthProtocolDirectedMessage {
+ internal interface IOAuthDirectedMessage : IDirectedProtocolMessage {
/// <summary>
/// Gets the preferred method of transport for the message.
/// </summary>
- MessageScheme PreferredScheme { get; }
+ HttpDeliveryMethod HttpMethods { get; }
}
}
diff --git a/src/DotNetOAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOAuth/ChannelElements/OAuthChannel.cs
index 7183fa5..acbb69b 100644
--- a/src/DotNetOAuth/ChannelElements/OAuthChannel.cs
+++ b/src/DotNetOAuth/ChannelElements/OAuthChannel.cs
@@ -7,6 +7,7 @@
namespace DotNetOAuth.ChannelElements {
using System;
using System.Collections.Generic;
+ using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
@@ -57,15 +58,9 @@ namespace DotNetOAuth.ChannelElements {
}
this.webRequestHandler = webRequestHandler;
- this.PreferredTransmissionScheme = MessageScheme.AuthorizationHeaderRequest;
}
/// <summary>
- /// Gets or sets the method used in direct requests to transmit the message payload.
- /// </summary>
- internal MessageScheme PreferredTransmissionScheme { get; set; }
-
- /// <summary>
/// Gets or sets the Consumer web application path.
/// </summary>
internal Uri Realm { get; set; }
@@ -171,22 +166,27 @@ namespace DotNetOAuth.ChannelElements {
if (request.Recipient == null) {
throw new ArgumentException(MessagingStrings.DirectedMessageMissingRecipient, "request");
}
+ IOAuthDirectedMessage oauthRequest = request as IOAuthDirectedMessage;
+ if (oauthRequest == null) {
+ throw new ArgumentException(
+ string.Format(
+ CultureInfo.CurrentCulture,
+ MessagingStrings.UnexpectedType,
+ typeof(IOAuthDirectedMessage),
+ request.GetType()));
+ }
HttpWebRequest httpRequest;
- MessageScheme transmissionMethod = this.PreferredTransmissionScheme;
- switch (transmissionMethod) {
- case MessageScheme.AuthorizationHeaderRequest:
- httpRequest = this.InitializeRequestAsAuthHeader(request);
- break;
- case MessageScheme.PostRequest:
- httpRequest = this.InitializeRequestAsPost(request);
- break;
- case MessageScheme.GetRequest:
- httpRequest = InitializeRequestAsGet(request);
- break;
- default:
- throw new NotSupportedException();
+ HttpDeliveryMethod transmissionMethod = oauthRequest.HttpMethods;
+ if ((transmissionMethod & HttpDeliveryMethod.AuthorizationHeaderRequest) != 0) {
+ httpRequest = this.InitializeRequestAsAuthHeader(request);
+ } else if ((transmissionMethod & HttpDeliveryMethod.PostRequest) != 0) {
+ httpRequest = this.InitializeRequestAsPost(request);
+ } else if ((transmissionMethod & HttpDeliveryMethod.GetRequest) != 0) {
+ httpRequest = InitializeRequestAsGet(request);
+ } else {
+ throw new NotSupportedException();
}
Response response = this.webRequestHandler.GetResponse(httpRequest);
diff --git a/src/DotNetOAuth/Consumer.cs b/src/DotNetOAuth/Consumer.cs
index 1a73d5f..a3af2bc 100644
--- a/src/DotNetOAuth/Consumer.cs
+++ b/src/DotNetOAuth/Consumer.cs
@@ -5,9 +5,39 @@
//-----------------------------------------------------------------------
namespace DotNetOAuth {
+ using DotNetOAuth.Messages;
+
/// <summary>
/// A website or application that uses OAuth to access the Service Provider on behalf of the User.
/// </summary>
internal class Consumer {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Consumer"/> class.
+ /// </summary>
+ internal Consumer() {
+ }
+
+ /// <summary>
+ /// Gets or sets the Consumer Key used to communicate with the Service Provider.
+ /// </summary>
+ public string ConsumerKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Consumer Secret used to communicate with the Service Provider.
+ /// </summary>
+ public string ConsumerSecret { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Service Provider that will be accessed.
+ /// </summary>
+ public ServiceProvider ServiceProvider { get; set; }
+
+ /// <summary>
+ /// Begins an OAuth authorization request and redirects the user to the Service Provider
+ /// to provide that authorization.
+ /// </summary>
+ public void RequestUserAuthorization() {
+ RequestTokenMessage requestToken = new RequestTokenMessage(ServiceProvider.RequestTokenEndpoint);
+ }
}
}
diff --git a/src/DotNetOAuth/DotNetOAuth.csproj b/src/DotNetOAuth/DotNetOAuth.csproj
index d2e8b31..7e7b567 100644
--- a/src/DotNetOAuth/DotNetOAuth.csproj
+++ b/src/DotNetOAuth/DotNetOAuth.csproj
@@ -52,6 +52,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
+ <Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.XML" />
</ItemGroup>
@@ -78,7 +79,7 @@
<Compile Include="Messaging\Bindings\IExpiringProtocolMessage.cs" />
<Compile Include="Messages\AccessProtectedResourcesMessage.cs" />
<Compile Include="Messages\GrantAccessTokenMessage.cs" />
- <Compile Include="ChannelElements\IOAuthProtocolDirectedMessage.cs" />
+ <Compile Include="ChannelElements\IOAuthDirectedMessage.cs" />
<Compile Include="Messages\DirectUserToConsumerMessage.cs" />
<Compile Include="Messages\DirectUserToServiceProviderMessage.cs" />
<Compile Include="Messages\UnauthorizedRequestTokenMessage.cs" />
@@ -108,7 +109,7 @@
<Compile Include="Loggers\Log4NetLogger.cs" />
<Compile Include="Loggers\NoOpLogger.cs" />
<Compile Include="Loggers\TraceLogger.cs" />
- <Compile Include="Messaging\MessageScheme.cs" />
+ <Compile Include="Messaging\HttpDeliveryMethod.cs" />
<Compile Include="Messaging\MessageTransport.cs" />
<Compile Include="ChannelElements\OAuthMessageTypeProvider.cs" />
<Compile Include="Messaging\ProtocolException.cs" />
@@ -116,6 +117,7 @@
<Compile Include="Messages\RequestTokenMessage.cs" />
<Compile Include="ChannelElements\RsaSha1SigningBindingElement.cs" />
<Compile Include="ChannelElements\StandardWebRequestHandler.cs" />
+ <Compile Include="ServiceProviderEndpoint.cs" />
<Compile Include="Util.cs" />
<Compile Include="Protocol.cs" />
<Compile Include="ServiceProvider.cs" />
diff --git a/src/DotNetOAuth/Messages/AccessProtectedResourcesMessage.cs b/src/DotNetOAuth/Messages/AccessProtectedResourcesMessage.cs
index 05eba68..8b8c1d5 100644
--- a/src/DotNetOAuth/Messages/AccessProtectedResourcesMessage.cs
+++ b/src/DotNetOAuth/Messages/AccessProtectedResourcesMessage.cs
@@ -17,7 +17,7 @@ namespace DotNetOAuth.Messages {
/// Initializes a new instance of the <see cref="AccessProtectedResourcesMessage"/> class.
/// </summary>
/// <param name="serviceProvider">The URI of the Service Provider endpoint to send this message to.</param>
- internal AccessProtectedResourcesMessage(Uri serviceProvider)
+ internal AccessProtectedResourcesMessage(ServiceProviderEndpoint serviceProvider)
: base(MessageTransport.Direct, serviceProvider) {
}
diff --git a/src/DotNetOAuth/Messages/DirectUserToConsumerMessage.cs b/src/DotNetOAuth/Messages/DirectUserToConsumerMessage.cs
index 8d5a6a3..8cd6abb 100644
--- a/src/DotNetOAuth/Messages/DirectUserToConsumerMessage.cs
+++ b/src/DotNetOAuth/Messages/DirectUserToConsumerMessage.cs
@@ -16,7 +16,7 @@ namespace DotNetOAuth.Messages {
/// Initializes a new instance of the <see cref="DirectUserToConsumerMessage"/> class.
/// </summary>
/// <param name="consumer">The URI of the Consumer endpoint to send this message to.</param>
- internal DirectUserToConsumerMessage(Uri consumer)
+ internal DirectUserToConsumerMessage(ServiceProviderEndpoint consumer)
: base(MessageProtection.None, MessageTransport.Indirect, consumer) {
}
diff --git a/src/DotNetOAuth/Messages/DirectUserToServiceProviderMessage.cs b/src/DotNetOAuth/Messages/DirectUserToServiceProviderMessage.cs
index 37cd004..629c0e2 100644
--- a/src/DotNetOAuth/Messages/DirectUserToServiceProviderMessage.cs
+++ b/src/DotNetOAuth/Messages/DirectUserToServiceProviderMessage.cs
@@ -16,7 +16,7 @@ namespace DotNetOAuth.Messages {
/// Initializes a new instance of the <see cref="DirectUserToServiceProviderMessage"/> class.
/// </summary>
/// <param name="serviceProvider">The URI of the Service Provider endpoint to send this message to.</param>
- internal DirectUserToServiceProviderMessage(Uri serviceProvider)
+ internal DirectUserToServiceProviderMessage(ServiceProviderEndpoint serviceProvider)
: base(MessageProtection.None, MessageTransport.Indirect, serviceProvider) {
}
diff --git a/src/DotNetOAuth/Messages/MessageBase.cs b/src/DotNetOAuth/Messages/MessageBase.cs
index db5830c..599cc4f 100644
--- a/src/DotNetOAuth/Messages/MessageBase.cs
+++ b/src/DotNetOAuth/Messages/MessageBase.cs
@@ -14,7 +14,7 @@ namespace DotNetOAuth.Messages {
/// <summary>
/// A base class for all OAuth messages.
/// </summary>
- internal abstract class MessageBase : IDirectedProtocolMessage {
+ internal abstract class MessageBase : IOAuthDirectedMessage {
/// <summary>
/// A store for extra name/value data pairs that are attached to this message.
/// </summary>
@@ -33,7 +33,7 @@ namespace DotNetOAuth.Messages {
/// <summary>
/// The URI to the remote endpoint to send this message to.
/// </summary>
- private Uri recipient;
+ private ServiceProviderEndpoint recipient;
/// <summary>
/// Initializes a new instance of the <see cref="MessageBase"/> class.
@@ -51,7 +51,7 @@ namespace DotNetOAuth.Messages {
/// <param name="protectionRequired">The level of protection the message requires.</param>
/// <param name="transport">A value indicating whether this message requires a direct or indirect transport.</param>
/// <param name="recipient">The URI that a directed message will be delivered to.</param>
- protected MessageBase(MessageProtection protectionRequired, MessageTransport transport, Uri recipient) {
+ protected MessageBase(MessageProtection protectionRequired, MessageTransport transport, ServiceProviderEndpoint recipient) {
if (recipient == null) {
throw new ArgumentNullException("recipient");
}
@@ -99,7 +99,18 @@ namespace DotNetOAuth.Messages {
/// Gets the URI to the Service Provider endpoint to send this message to.
/// </summary>
Uri IDirectedProtocolMessage.Recipient {
- get { return this.recipient; }
+ get { return this.recipient.Location; }
+ }
+
+ #endregion
+
+ #region IOAuthDirectedMessage Properties
+
+ /// <summary>
+ /// Gets the preferred method of transport for the message.
+ /// </summary>
+ HttpDeliveryMethod IOAuthDirectedMessage.HttpMethods {
+ get { return this.recipient.AllowedMethods; }
}
#endregion
diff --git a/src/DotNetOAuth/Messages/RequestAccessTokenMessage.cs b/src/DotNetOAuth/Messages/RequestAccessTokenMessage.cs
index 4622009..143b67d 100644
--- a/src/DotNetOAuth/Messages/RequestAccessTokenMessage.cs
+++ b/src/DotNetOAuth/Messages/RequestAccessTokenMessage.cs
@@ -17,7 +17,7 @@ namespace DotNetOAuth.Messages {
/// Initializes a new instance of the <see cref="RequestAccessTokenMessage"/> class.
/// </summary>
/// <param name="serviceProvider">The URI of the Service Provider endpoint to send this message to.</param>
- internal RequestAccessTokenMessage(Uri serviceProvider)
+ internal RequestAccessTokenMessage(ServiceProviderEndpoint serviceProvider)
: base(MessageTransport.Direct, serviceProvider) {
}
diff --git a/src/DotNetOAuth/Messages/RequestTokenMessage.cs b/src/DotNetOAuth/Messages/RequestTokenMessage.cs
index 11d2dd1..2a8cdfe 100644
--- a/src/DotNetOAuth/Messages/RequestTokenMessage.cs
+++ b/src/DotNetOAuth/Messages/RequestTokenMessage.cs
@@ -16,7 +16,7 @@ namespace DotNetOAuth.Messages {
/// Initializes a new instance of the <see cref="RequestTokenMessage"/> class.
/// </summary>
/// <param name="serviceProvider">The URI of the Service Provider endpoint to send this message to.</param>
- internal RequestTokenMessage(Uri serviceProvider)
+ internal RequestTokenMessage(ServiceProviderEndpoint serviceProvider)
: base(MessageTransport.Direct, serviceProvider) {
}
diff --git a/src/DotNetOAuth/Messages/SignedMessageBase.cs b/src/DotNetOAuth/Messages/SignedMessageBase.cs
index bc5d48e..f490b26 100644
--- a/src/DotNetOAuth/Messages/SignedMessageBase.cs
+++ b/src/DotNetOAuth/Messages/SignedMessageBase.cs
@@ -39,7 +39,7 @@ namespace DotNetOAuth.Messages {
/// </summary>
/// <param name="transport">A value indicating whether this message requires a direct or indirect transport.</param>
/// <param name="recipient">The URI that a directed message will be delivered to.</param>
- internal SignedMessageBase(MessageTransport transport, Uri recipient)
+ internal SignedMessageBase(MessageTransport transport, ServiceProviderEndpoint recipient)
: base(MessageProtection.All, transport, recipient) {
}
diff --git a/src/DotNetOAuth/Messaging/MessageScheme.cs b/src/DotNetOAuth/Messaging/HttpDeliveryMethod.cs
index 2c0aec1..b4b8c42 100644
--- a/src/DotNetOAuth/Messaging/MessageScheme.cs
+++ b/src/DotNetOAuth/Messaging/HttpDeliveryMethod.cs
@@ -1,35 +1,43 @@
//-----------------------------------------------------------------------
-// <copyright file="MessageScheme.cs" company="Andrew Arnott">
+// <copyright file="HttpDeliveryMethod.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOAuth.Messaging {
+ using System;
+
/// <summary>
/// The methods available for the Consumer to send direct messages to the Service Provider.
/// </summary>
/// <remarks>
/// See 1.0 spec section 5.2.
/// </remarks>
- internal enum MessageScheme {
+ [Flags]
+ public enum HttpDeliveryMethod {
+ /// <summary>
+ /// No HTTP methods are allowed.
+ /// </summary>
+ None = 0x0,
+
/// <summary>
/// In the HTTP Authorization header as defined in OAuth HTTP Authorization Scheme (OAuth HTTP Authorization Scheme).
/// </summary>
- AuthorizationHeaderRequest,
+ AuthorizationHeaderRequest = 0x1,
/// <summary>
/// As the HTTP POST request body with a content-type of application/x-www-form-urlencoded.
/// </summary>
- PostRequest,
+ PostRequest = 0x2,
/// <summary>
/// Added to the URLs in the query part (as defined by [RFC3986] (Berners-Lee, T., “Uniform Resource Identifiers (URI): Generic Syntax,” .) section 3).
/// </summary>
- GetRequest,
+ GetRequest = 0x4,
/// <summary>
- /// Response parameters are sent by the Service Provider to return Tokens and other information to the Consumer in the HTTP response body. The parameter names and values are first encoded as per Parameter Encoding (Parameter Encoding), and concatenated with the ‘&amp;’ character (ASCII code 38) as defined in [RFC3986] (Berners-Lee, T., “Uniform Resource Identifiers (URI): Generic Syntax,” .) Section 2.1.
+ /// All HTTP requests are acceptable.
/// </summary>
- QueryStyleResponse,
+ All = AuthorizationHeaderRequest | PostRequest | GetRequest,
}
}
diff --git a/src/DotNetOAuth/ServiceProvider.cs b/src/DotNetOAuth/ServiceProvider.cs
index 7cf41cc..812a6a8 100644
--- a/src/DotNetOAuth/ServiceProvider.cs
+++ b/src/DotNetOAuth/ServiceProvider.cs
@@ -23,9 +23,9 @@ namespace DotNetOAuth {
/// </remarks>
internal class ServiceProvider {
/// <summary>
- /// The field used to store the value of the <see cref="RequestTokenUri"/> property.
+ /// The field used to store the value of the <see cref="RequestTokenEndpoint"/> property.
/// </summary>
- private Uri requestTokenUri;
+ private ServiceProviderEndpoint requestTokenEndpoint;
/// <summary>
/// Gets or sets the URL used to obtain an unauthorized Request Token,
@@ -36,16 +36,17 @@ namespace DotNetOAuth {
/// This is the URL that <see cref="Messages.RequestTokenMessage"/> messages are directed to.
/// </remarks>
/// <exception cref="ArgumentException">Thrown if this property is set to a URI with OAuth protocol parameters.</exception>
- public Uri RequestTokenUri {
+ public ServiceProviderEndpoint RequestTokenEndpoint {
get {
- return this.requestTokenUri;
+ return this.requestTokenEndpoint;
}
set {
- if (UriUtil.QueryStringContainsOAuthParameters(value)) {
+ if (value != null && UriUtil.QueryStringContainsOAuthParameters(value.Location)) {
throw new ArgumentException(Strings.RequestUrlMustNotHaveOAuthParameters);
}
- this.requestTokenUri = value;
+
+ this.requestTokenEndpoint = value;
}
}
@@ -57,7 +58,7 @@ namespace DotNetOAuth {
/// This is the URL that <see cref="Messages.DirectUserToServiceProviderMessage"/> messages are
/// indirectly (via the user agent) sent to.
/// </remarks>
- public Uri UserAuthorizationUri { get; set; }
+ public ServiceProviderEndpoint UserAuthorizationEndpoint { get; set; }
/// <summary>
/// Gets or sets the URL used to exchange the User-authorized Request Token
@@ -66,6 +67,6 @@ namespace DotNetOAuth {
/// <remarks>
/// This is the URL that <see cref="Messages.RequestAccessTokenMessage"/> messages are directed to.
/// </remarks>
- public Uri AccessTokenUri { get; set; }
+ public ServiceProviderEndpoint AccessTokenEndpoint { get; set; }
}
}
diff --git a/src/DotNetOAuth/ServiceProviderEndpoint.cs b/src/DotNetOAuth/ServiceProviderEndpoint.cs
new file mode 100644
index 0000000..89f5e61
--- /dev/null
+++ b/src/DotNetOAuth/ServiceProviderEndpoint.cs
@@ -0,0 +1,53 @@
+//-----------------------------------------------------------------------
+// <copyright file="ServiceProviderEndpoint.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOAuth.Messaging;
+
+ /// <summary>
+ /// A description of an individual endpoint on a Service Provider.
+ /// </summary>
+ public class ServiceProviderEndpoint {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ServiceProviderEndpoint"/> class.
+ /// </summary>
+ /// <param name="locationUri">The URL of this Service Provider endpoint.</param>
+ /// <param name="method">The HTTP method(s) allowed.</param>
+ public ServiceProviderEndpoint(string locationUri, HttpDeliveryMethod method)
+ : this(new Uri(locationUri), method) { }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ServiceProviderEndpoint"/> class.
+ /// </summary>
+ /// <param name="location">The URL of this Service Provider endpoint.</param>
+ /// <param name="method">The HTTP method(s) allowed.</param>
+ public ServiceProviderEndpoint(Uri location, HttpDeliveryMethod method) {
+ if (location == null) {
+ throw new ArgumentNullException("location");
+ }
+ if (method == HttpDeliveryMethod.None) {
+ throw new ArgumentOutOfRangeException("method");
+ }
+
+ this.Location = location;
+ this.AllowedMethods = method;
+ }
+
+ /// <summary>
+ /// Gets or sets the URL of this Service Provider endpoint.
+ /// </summary>
+ public Uri Location { get; set; }
+
+ /// <summary>
+ /// Gets or sets the HTTP method(s) allowed.
+ /// </summary>
+ public HttpDeliveryMethod AllowedMethods { get; set; }
+ }
+}