summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs6
-rw-r--r--src/DotNetOAuth.Test/Scenarios/Coordinator.cs2
-rw-r--r--src/DotNetOAuth/Messaging/Channel.cs25
-rw-r--r--src/DotNetOAuth/Messaging/HttpRequestInfo.cs2
-rw-r--r--src/DotNetOAuth/ServiceProvider.cs28
5 files changed, 40 insertions, 23 deletions
diff --git a/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs b/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs
index 7a03859..6cc9a85 100644
--- a/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOAuth.Test/ChannelElements/OAuthChannelTests.cs
@@ -102,7 +102,8 @@ namespace DotNetOAuth.Test.ChannelElements {
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void ReadFromResponseNull() {
- this.channel.ReadFromResponse(null);
+ Channel_Accessor accessor = Channel_Accessor.AttachShadow(this.channel);
+ accessor.ReadFromResponse(null);
}
[TestMethod]
@@ -119,7 +120,8 @@ namespace DotNetOAuth.Test.ChannelElements {
writer.Write(MessagingUtilities.CreateQueryString(fields));
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
- IProtocolMessage message = this.channel.ReadFromResponse(ms);
+ Channel_Accessor channelAccessor = Channel_Accessor.AttachShadow(this.channel);
+ IProtocolMessage message = channelAccessor.ReadFromResponse(ms);
Assert.IsNotNull(message);
Assert.IsInstanceOfType(message, typeof(TestMessage));
TestMessage testMessage = (TestMessage)message;
diff --git a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
index f11c63e..f03e8d8 100644
--- a/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
+++ b/src/DotNetOAuth.Test/Scenarios/Coordinator.cs
@@ -73,7 +73,7 @@ namespace DotNetOAuth.Test.Scenarios {
ConsumerKey = this.consumerDescription.ConsumerKey,
};
ServiceProvider serviceProvider = new ServiceProvider(this.serviceDescription, serviceTokenManager) {
- Channel = serviceProviderChannel,
+ OAuthChannel = serviceProviderChannel,
};
Thread consumerThread = null, serviceProviderThread = null;
diff --git a/src/DotNetOAuth/Messaging/Channel.cs b/src/DotNetOAuth/Messaging/Channel.cs
index 09e20b9..77263eb 100644
--- a/src/DotNetOAuth/Messaging/Channel.cs
+++ b/src/DotNetOAuth/Messaging/Channel.cs
@@ -20,7 +20,7 @@ namespace DotNetOAuth.Messaging {
/// <summary>
/// Manages sending direct messages to a remote party and receiving responses.
/// </summary>
- internal abstract class Channel {
+ public abstract class Channel {
/// <summary>
/// The maximum allowable size for a 301 Redirect response before we send
/// a 200 OK response with a scripted form POST with the parameters instead
@@ -106,7 +106,7 @@ namespace DotNetOAuth.Messaging {
/// </summary>
/// <param name="message">The one-way message to send</param>
/// <returns>The pending user agent redirect based message to be sent as an HttpResponse.</returns>
- internal Response Send(IProtocolMessage message) {
+ public Response Send(IProtocolMessage message) {
if (message == null) {
throw new ArgumentNullException("message");
}
@@ -150,7 +150,7 @@ namespace DotNetOAuth.Messaging {
/// Requires an HttpContext.Current context.
/// </remarks>
/// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
- internal IProtocolMessage ReadFromRequest() {
+ public IProtocolMessage ReadFromRequest() {
return this.ReadFromRequest(this.GetRequestFromContext());
}
@@ -165,7 +165,7 @@ namespace DotNetOAuth.Messaging {
/// </remarks>
/// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
/// <exception cref="ProtocolException">Thrown when a request message of an unexpected type is received.</exception>
- internal bool TryReadFromRequest<TREQUEST>(out TREQUEST request)
+ public bool TryReadFromRequest<TREQUEST>(out TREQUEST request)
where TREQUEST : class, IProtocolMessage {
return TryReadFromRequest<TREQUEST>(this.GetRequestFromContext(), out request);
}
@@ -177,12 +177,9 @@ namespace DotNetOAuth.Messaging {
/// <param name="httpRequest">The request to search for an embedded message.</param>
/// <param name="request">The deserialized message, if one is found. Null otherwise.</param>
/// <returns>True if the expected message was recognized and deserialized. False otherwise.</returns>
- /// <remarks>
- /// Requires an HttpContext.Current context.
- /// </remarks>
/// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
/// <exception cref="ProtocolException">Thrown when a request message of an unexpected type is received.</exception>
- internal bool TryReadFromRequest<TREQUEST>(HttpRequestInfo httpRequest, out TREQUEST request)
+ public bool TryReadFromRequest<TREQUEST>(HttpRequestInfo httpRequest, out TREQUEST request)
where TREQUEST : class, IProtocolMessage {
IProtocolMessage untypedRequest = this.ReadFromRequest(httpRequest);
if (untypedRequest == null) {
@@ -213,7 +210,7 @@ namespace DotNetOAuth.Messaging {
/// </remarks>
/// <exception cref="InvalidOperationException">Thrown when <see cref="HttpContext.Current"/> is null.</exception>
/// <exception cref="ProtocolException">Thrown if the expected message was not recognized in the response.</exception>
- internal TREQUEST ReadFromRequest<TREQUEST>()
+ public TREQUEST ReadFromRequest<TREQUEST>()
where TREQUEST : class, IProtocolMessage {
return this.ReadFromRequest<TREQUEST>(this.GetRequestFromContext());
}
@@ -225,7 +222,7 @@ namespace DotNetOAuth.Messaging {
/// <param name="httpRequest">The request to search for an embedded message.</param>
/// <returns>The deserialized message, if one is found. Null otherwise.</returns>
/// <exception cref="ProtocolException">Thrown if the expected message was not recognized in the response.</exception>
- protected internal TREQUEST ReadFromRequest<TREQUEST>(HttpRequestInfo httpRequest)
+ public TREQUEST ReadFromRequest<TREQUEST>(HttpRequestInfo httpRequest)
where TREQUEST : class, IProtocolMessage {
TREQUEST request;
if (this.TryReadFromRequest<TREQUEST>(httpRequest, out request)) {
@@ -244,7 +241,7 @@ namespace DotNetOAuth.Messaging {
/// </summary>
/// <param name="httpRequest">The request to search for an embedded message.</param>
/// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- protected internal IProtocolMessage ReadFromRequest(HttpRequestInfo httpRequest) {
+ public IProtocolMessage ReadFromRequest(HttpRequestInfo httpRequest) {
IProtocolMessage requestMessage = this.ReadFromRequestInternal(httpRequest);
if (requestMessage != null) {
Logger.DebugFormat("Incoming request received: {0}", requestMessage);
@@ -264,7 +261,7 @@ namespace DotNetOAuth.Messaging {
/// Thrown if no message is recognized in the response
/// or an unexpected type of message is received.
/// </exception>
- protected internal TRESPONSE Request<TRESPONSE>(IDirectedProtocolMessage request)
+ public TRESPONSE Request<TRESPONSE>(IDirectedProtocolMessage request)
where TRESPONSE : class, IProtocolMessage {
IProtocolMessage response = this.Request(request);
if (response == null) {
@@ -293,7 +290,7 @@ namespace DotNetOAuth.Messaging {
/// </summary>
/// <param name="request">The message to send.</param>
/// <returns>The remote party's response.</returns>
- protected internal IProtocolMessage Request(IDirectedProtocolMessage request) {
+ public IProtocolMessage Request(IDirectedProtocolMessage request) {
if (request == null) {
throw new ArgumentNullException("request");
}
@@ -314,7 +311,7 @@ namespace DotNetOAuth.Messaging {
/// </summary>
/// <param name="responseStream">The response that is anticipated to contain an OAuth message.</param>
/// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- protected internal IProtocolMessage ReadFromResponse(Stream responseStream) {
+ private IProtocolMessage ReadFromResponse(Stream responseStream) {
IProtocolMessage message = this.ReadFromResponseInternal(responseStream);
Logger.DebugFormat("Received message response: {0}", message);
this.VerifyMessageAfterReceiving(message);
diff --git a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs b/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
index efd9dec..3b037c6 100644
--- a/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
+++ b/src/DotNetOAuth/Messaging/HttpRequestInfo.cs
@@ -21,7 +21,7 @@ namespace DotNetOAuth.Messaging {
/// ASP.NET does not let us fully initialize that class, so we have to write one
/// of our one.
/// </remarks>
- internal class HttpRequestInfo {
+ public class HttpRequestInfo {
/// <summary>
/// The key/value pairs found in the entity of a POST request.
/// </summary>
diff --git a/src/DotNetOAuth/ServiceProvider.cs b/src/DotNetOAuth/ServiceProvider.cs
index f2e8730..48ccff4 100644
--- a/src/DotNetOAuth/ServiceProvider.cs
+++ b/src/DotNetOAuth/ServiceProvider.cs
@@ -56,7 +56,7 @@ namespace DotNetOAuth {
var signingElement = serviceDescription.CreateTamperProtectionElement();
INonceStore store = new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge);
this.ServiceDescription = serviceDescription;
- this.Channel = new OAuthChannel(signingElement, store, tokenManager, messageTypeProvider, new StandardWebRequestHandler());
+ this.OAuthChannel = new OAuthChannel(signingElement, store, tokenManager, messageTypeProvider, new StandardWebRequestHandler());
this.TokenGenerator = new StandardTokenGenerator();
}
@@ -74,13 +74,20 @@ namespace DotNetOAuth {
/// Gets the persistence store for tokens and secrets.
/// </summary>
public ITokenManager TokenManager {
- get { return this.Channel.TokenManager; }
+ get { return this.OAuthChannel.TokenManager; }
+ }
+
+ /// <summary>
+ /// Gets the channel to use for sending/receiving messages.
+ /// </summary>
+ public Channel Channel {
+ get { return this.OAuthChannel; }
}
/// <summary>
/// Gets or sets the channel to use for sending/receiving messages.
/// </summary>
- internal OAuthChannel Channel { get; set; }
+ internal OAuthChannel OAuthChannel { get; set; }
/// <summary>
/// Reads any incoming OAuth message.
@@ -216,7 +223,7 @@ namespace DotNetOAuth {
/// <param name="request">The Consumer's message requesting an access token.</param>
/// <param name="extraParameters">Any extra parameters the Consumer should receive with the OAuth message. May be null.</param>
/// <returns>The HTTP response to actually send to the Consumer.</returns>
- public Response SendAccessToken(GetAccessTokenMessage request, IDictionary<string, string> extraParameters) {
+ public GrantAccessTokenMessage PrepareAccessTokenMessage(GetAccessTokenMessage request) {
if (request == null) {
throw new ArgumentNullException("request");
}
@@ -236,8 +243,19 @@ namespace DotNetOAuth {
AccessToken = accessToken,
TokenSecret = tokenSecret,
};
- grantAccess.AddNonOAuthParameters(extraParameters);
+ return grantAccess;
+ }
+
+ /// <summary>
+ /// Prepares and sends an access token to a Consumer, and invalidates the request token.
+ /// </summary>
+ /// <param name="request">The Consumer's message requesting an access token.</param>
+ /// <param name="extraParameters">Any extra parameters the Consumer should receive with the OAuth message. May be null.</param>
+ /// <returns>The HTTP response to actually send to the Consumer.</returns>
+ public Response SendAccessToken(GetAccessTokenMessage request, IDictionary<string, string> extraParameters) {
+ var grantAccess = PrepareAccessTokenMessage(request);
+ grantAccess.AddNonOAuthParameters(extraParameters);
return this.Channel.Send(grantAccess);
}