diff options
-rw-r--r-- | src/DotNetOAuth/DotNetOAuth.csproj | 3 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/IndirectMessageEncoder.cs | 2 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/MessagingUtilities.cs | 44 | ||||
-rw-r--r-- | src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs (renamed from src/DotNetOAuth/Messaging/IndirectMessage.cs) | 34 | ||||
-rw-r--r-- | src/DotNetOAuth/Strings.Designer.cs | 9 | ||||
-rw-r--r-- | src/DotNetOAuth/Strings.resx | 3 |
6 files changed, 86 insertions, 9 deletions
diff --git a/src/DotNetOAuth/DotNetOAuth.csproj b/src/DotNetOAuth/DotNetOAuth.csproj index 2499282..618b0af 100644 --- a/src/DotNetOAuth/DotNetOAuth.csproj +++ b/src/DotNetOAuth/DotNetOAuth.csproj @@ -71,7 +71,8 @@ <Compile Include="Messaging\DictionaryXmlWriter.cs" />
<Compile Include="Messaging\DirectMessageChannel.cs" />
<Compile Include="Messaging\IProtocolMessageRequest.cs" />
- <Compile Include="Messaging\IndirectMessage.cs" />
+ <Compile Include="Messaging\MessagingUtilities.cs" />
+ <Compile Include="Messaging\ProtocolMessageResponse.cs" />
<Compile Include="Messaging\IndirectMessageEncoder.cs" />
<Compile Include="Messaging\IProtocolMessage.cs" />
<Compile Include="Logger.cs" />
diff --git a/src/DotNetOAuth/Messaging/IndirectMessageEncoder.cs b/src/DotNetOAuth/Messaging/IndirectMessageEncoder.cs index 54970d9..d17fb2a 100644 --- a/src/DotNetOAuth/Messaging/IndirectMessageEncoder.cs +++ b/src/DotNetOAuth/Messaging/IndirectMessageEncoder.cs @@ -14,7 +14,7 @@ namespace DotNetOAuth.Messaging { /// </summary>
/// <param name="message">The indirect message to send.</param>
/// <returns>The encoded message to send to the user agent.</returns>
- internal IndirectMessage Encode(IProtocolMessage message) {
+ internal ProtocolMessageResponse Encode(IProtocolMessage message) {
throw new System.NotImplementedException();
}
}
diff --git a/src/DotNetOAuth/Messaging/MessagingUtilities.cs b/src/DotNetOAuth/Messaging/MessagingUtilities.cs new file mode 100644 index 0000000..7544fa4 --- /dev/null +++ b/src/DotNetOAuth/Messaging/MessagingUtilities.cs @@ -0,0 +1,44 @@ +//-----------------------------------------------------------------------
+// <copyright file="MessagingUtilities.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOAuth.Messaging {
+ using System;
+ using System.Net;
+ using System.Web;
+
+ /// <summary>
+ /// A grab-bag of utility methods useful for the channel stack of the protocol.
+ /// </summary>
+ internal class MessagingUtilities {
+ /// <summary>
+ /// Adds a set of HTTP headers to an <see cref="HttpResponse"/> instance,
+ /// taking care to set some headers to the appropriate properties of
+ /// <see cref="HttpResponse" />
+ /// </summary>
+ /// <param name="headers">The headers to add.</param>
+ /// <param name="response">The <see cref="HttpResponse"/> instance to set the appropriate values to.</param>
+ internal static void ApplyHeadersToResponse(WebHeaderCollection headers, HttpResponse response) {
+ if (headers == null) {
+ throw new ArgumentNullException("headers");
+ }
+ if (response == null) {
+ throw new ArgumentNullException("response");
+ }
+ foreach (string headerName in headers) {
+ switch (headerName) {
+ case "Content-Type":
+ response.ContentType = headers[HttpResponseHeader.ContentType];
+ break;
+
+ // Add more special cases here as necessary.
+ default:
+ response.AddHeader(headerName, headers[headerName]);
+ break;
+ }
+ }
+ }
+ }
+}
diff --git a/src/DotNetOAuth/Messaging/IndirectMessage.cs b/src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs index 9a2624e..1f2d081 100644 --- a/src/DotNetOAuth/Messaging/IndirectMessage.cs +++ b/src/DotNetOAuth/Messaging/ProtocolMessageResponse.cs @@ -1,21 +1,29 @@ //-----------------------------------------------------------------------
-// <copyright file="IndirectMessage.cs" company="Andrew Arnott">
+// <copyright file="ProtocolMessageResponse.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOAuth.Messaging {
+ using System;
using System.Net;
+ using System.Web;
/// <summary>
- /// A protocol message that passes between Consumer and Service Provider
- /// via the user agent using a redirect or form POST submission.
+ /// A protocol message (request or response) that passes between Consumer and Service Provider
+ /// via the user agent using a redirect or form POST submission,
+ /// OR a direct message response.
/// </summary>
/// <remarks>
- /// An <see cref="IndirectMessage"/> instance describes the HTTP response that must
- /// be sent to the user agent to initiate the message transfer.
+ /// <para>An instance of this type describes the HTTP response that must be sent
+ /// in response to the current HTTP request.</para>
+ /// <para>It is important that this response make up the entire HTTP response.
+ /// A hosting ASPX page should not be allowed to render its normal HTML output
+ /// after this response is sent. The normal rendered output of an ASPX page
+ /// can be canceled by calling <see cref="HttpResponse.End"/> after this message
+ /// is sent on the response stream.</para>
/// </remarks>
- public class IndirectMessage {
+ public class ProtocolMessageResponse {
/// <summary>
/// Gets the headers that must be included in the response to the user agent.
/// </summary>
@@ -47,7 +55,19 @@ namespace DotNetOAuth.Messaging { /// Requires a current HttpContext.
/// </summary>
public void Send() {
- throw new System.NotImplementedException();
+ if (HttpContext.Current == null) {
+ throw new InvalidOperationException(Strings.CurrentHttpContextRequired);
+ }
+
+ HttpContext.Current.Response.Clear();
+ HttpContext.Current.Response.StatusCode = (int)this.Status;
+ MessagingUtilities.ApplyHeadersToResponse(this.Headers, HttpContext.Current.Response);
+ if (this.Body != null && this.Body.Length > 0) {
+ HttpContext.Current.Response.OutputStream.Write(this.Body, 0, this.Body.Length);
+ HttpContext.Current.Response.OutputStream.Flush();
+ }
+ HttpContext.Current.Response.OutputStream.Close();
+ HttpContext.Current.Response.End();
}
}
}
diff --git a/src/DotNetOAuth/Strings.Designer.cs b/src/DotNetOAuth/Strings.Designer.cs index 05bbbc8..47a4c1c 100644 --- a/src/DotNetOAuth/Strings.Designer.cs +++ b/src/DotNetOAuth/Strings.Designer.cs @@ -61,6 +61,15 @@ namespace DotNetOAuth { }
/// <summary>
+ /// Looks up a localized string similar to HttpContext.Current is null. There must be an ASP.NET request in process for this operation to succeed..
+ /// </summary>
+ internal static string CurrentHttpContextRequired {
+ get {
+ return ResourceManager.GetString("CurrentHttpContextRequired", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to An invalid OAuth message received and discarded..
/// </summary>
internal static string InvalidIncomingMessage {
diff --git a/src/DotNetOAuth/Strings.resx b/src/DotNetOAuth/Strings.resx index 6c687d9..0e718d8 100644 --- a/src/DotNetOAuth/Strings.resx +++ b/src/DotNetOAuth/Strings.resx @@ -117,6 +117,9 @@ <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
+ <data name="CurrentHttpContextRequired" xml:space="preserve">
+ <value>HttpContext.Current is null. There must be an ASP.NET request in process for this operation to succeed.</value>
+ </data>
<data name="InvalidIncomingMessage" xml:space="preserve">
<value>An invalid OAuth message received and discarded.</value>
</data>
|