diff options
17 files changed, 61 insertions, 44 deletions
diff --git a/samples/Consumer/SampleWcf.aspx.cs b/samples/Consumer/SampleWcf.aspx.cs index d8cdc4f..db58cea 100644 --- a/samples/Consumer/SampleWcf.aspx.cs +++ b/samples/Consumer/SampleWcf.aspx.cs @@ -42,7 +42,7 @@ public partial class SampleWcf : System.Web.UI.Page { { "scope", scope }, }; var response = consumer.PrepareRequestUserAuthorization(callback.Uri, requestParams, null); - consumer.Channel.Send(response).Send(); + consumer.Channel.Send(response); } protected void getNameButton_Click(object sender, EventArgs e) { diff --git a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs index 81589c7..2206fff 100644 --- a/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs +++ b/samples/DotNetOpenAuth.ApplicationBlock/GoogleConsumer.cs @@ -95,7 +95,7 @@ namespace DotNetOpenAuth.ApplicationBlock { }; Uri callback = Util.GetCallbackUrlFromContext(); var request = consumer.PrepareRequestUserAuthorization(callback, extraParameters, null); - consumer.Channel.Send(request).Send(); + consumer.Channel.Send(request); } /// <summary> diff --git a/samples/ServiceProvider/Members/Authorize.aspx.cs b/samples/ServiceProvider/Members/Authorize.aspx.cs index 64c9700..76eec26 100644 --- a/samples/ServiceProvider/Members/Authorize.aspx.cs +++ b/samples/ServiceProvider/Members/Authorize.aspx.cs @@ -32,7 +32,7 @@ public partial class Authorize : System.Web.UI.Page { ServiceProvider sp = new ServiceProvider(Constants.SelfDescription, Global.TokenManager); var response = sp.PrepareAuthorizationResponse(pending); if (response != null) { - sp.Channel.Send(response).Send(); + sp.Channel.Send(response); } } diff --git a/samples/ServiceProvider/OAuth.ashx b/samples/ServiceProvider/OAuth.ashx index 506b900..46a516f 100644 --- a/samples/ServiceProvider/OAuth.ashx +++ b/samples/ServiceProvider/OAuth.ashx @@ -23,13 +23,13 @@ public class OAuth : IHttpHandler, IRequiresSessionState { AuthorizedTokenRequest requestAccessToken; if ((requestToken = request as RequestScopedTokenMessage) != null) { var response = sp.PrepareUnauthorizedTokenMessage(requestToken); - sp.Channel.Send(response).Send(); + sp.Channel.Send(response); } else if ((requestAuth = request as UserAuthorizationRequest) != null) { Global.PendingOAuthAuthorization = requestAuth; HttpContext.Current.Response.Redirect("~/Members/Authorize.aspx"); } else if ((requestAccessToken = request as AuthorizedTokenRequest) != null) { var response = sp.PrepareAccessTokenMessage(requestAccessToken); - sp.Channel.Send(response).Send(); + sp.Channel.Send(response); } else { throw new InvalidOperationException(); } diff --git a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs index 69f95f9..cbaded1 100644 --- a/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/Bindings/StandardExpirationBindingElementTests.cs @@ -20,7 +20,7 @@ namespace DotNetOpenAuth.Test.Messaging.Bindings { ((IExpiringProtocolMessage)message).UtcCreationDate = DateTime.Parse("1/1/1990"); Channel channel = CreateChannel(MessageProtections.Expiration); - channel.Send(message); + channel.PrepareResponse(message); Assert.IsTrue(DateTime.UtcNow - ((IExpiringProtocolMessage)message).UtcCreationDate < TimeSpan.FromSeconds(3), "The timestamp on the message was not set on send."); } diff --git a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs index 29154ed..ef8098e 100644 --- a/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs +++ b/src/DotNetOpenAuth.Test/Messaging/ChannelTests.cs @@ -36,25 +36,25 @@ namespace DotNetOpenAuth.Test.Messaging { [TestMethod, ExpectedException(typeof(ArgumentNullException))] public void SendNull() { - this.Channel.Send(null); + this.Channel.PrepareResponse(null); } [TestMethod, ExpectedException(typeof(ArgumentException))] public void SendIndirectedUndirectedMessage() { IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect); - this.Channel.Send(message); + this.Channel.PrepareResponse(message); } [TestMethod, ExpectedException(typeof(ArgumentException))] public void SendDirectedNoRecipientMessage() { IProtocolMessage message = new TestDirectedMessage(MessageTransport.Indirect); - this.Channel.Send(message); + this.Channel.PrepareResponse(message); } [TestMethod, ExpectedException(typeof(ArgumentException))] public void SendInvalidMessageTransport() { IProtocolMessage message = new TestDirectedMessage((MessageTransport)100); - this.Channel.Send(message); + this.Channel.PrepareResponse(message); } [TestMethod] @@ -64,7 +64,7 @@ namespace DotNetOpenAuth.Test.Messaging { message.Recipient = new Uri("http://provider/path"); var expected = GetStandardTestFields(FieldFill.CompleteBeforeBindings); - UserAgentResponse response = this.Channel.Send(message); + UserAgentResponse response = this.Channel.PrepareResponse(message); Assert.AreEqual(HttpStatusCode.Redirect, response.Status); StringAssert.StartsWith(response.Headers[HttpResponseHeader.Location], "http://provider/path"); foreach (var pair in expected) { @@ -107,7 +107,7 @@ namespace DotNetOpenAuth.Test.Messaging { Location = new Uri("http://host/path"), Recipient = new Uri("http://provider/path"), }; - UserAgentResponse response = this.Channel.Send(message); + UserAgentResponse response = this.Channel.PrepareResponse(message); Assert.AreEqual(HttpStatusCode.OK, response.Status, "A form redirect should be an HTTP successful response."); Assert.IsNull(response.Headers[HttpResponseHeader.Location], "There should not be a redirection header in the response."); string body = response.Body; @@ -155,7 +155,7 @@ namespace DotNetOpenAuth.Test.Messaging { Name = "Andrew", Location = new Uri("http://host/path"), }; - this.Channel.Send(message); + this.Channel.PrepareResponse(message); } [TestMethod, ExpectedException(typeof(ArgumentNullException))] @@ -206,7 +206,7 @@ namespace DotNetOpenAuth.Test.Messaging { message.Recipient = new Uri("http://localtest"); this.Channel = CreateChannel(MessageProtections.ReplayProtection); - this.Channel.Send(message); + this.Channel.PrepareResponse(message); Assert.IsNotNull(((IReplayProtectedProtocolMessage)message).Nonce); } @@ -274,7 +274,7 @@ namespace DotNetOpenAuth.Test.Messaging { public void InsufficientlyProtectedMessageSent() { var message = new TestSignedDirectedMessage(MessageTransport.Direct); message.Recipient = new Uri("http://localtest"); - this.Channel.Send(message); + this.Channel.PrepareResponse(message); } [TestMethod, ExpectedException(typeof(UnprotectedMessageException))] diff --git a/src/DotNetOpenAuth.Test/OAuth/AppendixScenarios.cs b/src/DotNetOpenAuth.Test/OAuth/AppendixScenarios.cs index 527c48b..aaac447 100644 --- a/src/DotNetOpenAuth.Test/OAuth/AppendixScenarios.cs +++ b/src/DotNetOpenAuth.Test/OAuth/AppendixScenarios.cs @@ -34,7 +34,7 @@ namespace DotNetOpenAuth.Test.OAuth { consumerDescription, serviceDescription, consumer => { - consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(new Uri("http://printer.example.com/request_token_ready"), null, null)); // .Send() dropped because this is just a simulation + consumer.Channel.PrepareResponse(consumer.PrepareRequestUserAuthorization(new Uri("http://printer.example.com/request_token_ready"), null, null)); // .Send() dropped because this is just a simulation string accessToken = consumer.ProcessUserAuthorization().AccessToken; var photoRequest = consumer.CreateAuthorizingMessage(accessPhotoEndpoint, accessToken); UserAgentResponse protectedPhoto = ((CoordinatingOAuthChannel)consumer.Channel).RequestProtectedResource(photoRequest); @@ -45,12 +45,12 @@ namespace DotNetOpenAuth.Test.OAuth { }, sp => { var requestTokenMessage = sp.ReadTokenRequest(); - sp.Channel.Send(sp.PrepareUnauthorizedTokenMessage(requestTokenMessage)); // .Send() dropped because this is just a simulation + sp.Channel.PrepareResponse(sp.PrepareUnauthorizedTokenMessage(requestTokenMessage)); // .Send() dropped because this is just a simulation var authRequest = sp.ReadAuthorizationRequest(); ((InMemoryTokenManager)sp.TokenManager).AuthorizeRequestToken(authRequest.RequestToken); - sp.Channel.Send(sp.PrepareAuthorizationResponse(authRequest)); // .Send() dropped because this is just a simulation + sp.Channel.PrepareResponse(sp.PrepareAuthorizationResponse(authRequest)); // .Send() dropped because this is just a simulation var accessRequest = sp.ReadAccessTokenRequest(); - sp.Channel.Send(sp.PrepareAccessTokenMessage(accessRequest)); // .Send() dropped because this is just a simulation + sp.Channel.PrepareResponse(sp.PrepareAccessTokenMessage(accessRequest)); // .Send() dropped because this is just a simulation string accessToken = sp.ReadProtectedResourceAuthorization().AccessToken; ((CoordinatingOAuthChannel)sp.Channel).SendDirectRawResponse(new UserAgentResponse { ResponseStream = new MemoryStream(new byte[] { 0x33, 0x66 }), diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs index 10e9795..a74a622 100644 --- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs +++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs @@ -85,7 +85,7 @@ namespace DotNetOpenAuth.Test.ChannelElements { Location = new Uri("http://hostb/pathB"), }; - UserAgentResponse response = this.channel.Send(message); + UserAgentResponse response = this.channel.PrepareResponse(message); Assert.AreSame(message, response.OriginalMessage); Assert.AreEqual(HttpStatusCode.OK, response.Status); Assert.AreEqual(0, response.Headers.Count); diff --git a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs index 5e356a0..a6fb9de 100644 --- a/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/AssociationHandshakeTests.cs @@ -144,7 +144,7 @@ namespace DotNetOpenAuth.Test.OpenId { AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); renegotiateResponse.AssociationType = "HMAC-UNKNOWN"; renegotiateResponse.SessionType = "DH-UNKNOWN"; - op.Channel.Send(renegotiateResponse).Send(); + op.Channel.Send(renegotiateResponse); }); coordinator.Run(); } @@ -168,7 +168,7 @@ namespace DotNetOpenAuth.Test.OpenId { AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1; renegotiateResponse.SessionType = protocol.Args.SessionType.NoEncryption; - op.Channel.Send(renegotiateResponse).Send(); + op.Channel.Send(renegotiateResponse); }); coordinator.Run(); } @@ -193,7 +193,7 @@ namespace DotNetOpenAuth.Test.OpenId { AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1; renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA256; - op.Channel.Send(renegotiateResponse).Send(); + op.Channel.Send(renegotiateResponse); }); coordinator.Run(); } @@ -218,7 +218,7 @@ namespace DotNetOpenAuth.Test.OpenId { AssociateUnsuccessfulResponse renegotiateResponse = new AssociateUnsuccessfulResponse(request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA1; renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA1; - op.Channel.Send(renegotiateResponse).Send(); + op.Channel.Send(renegotiateResponse); // Receive second-try request = op.Channel.ReadFromRequest<AssociateRequest>(); @@ -227,7 +227,7 @@ namespace DotNetOpenAuth.Test.OpenId { renegotiateResponse = new AssociateUnsuccessfulResponse(request); renegotiateResponse.AssociationType = protocol.Args.SignatureAlgorithm.HMAC_SHA256; renegotiateResponse.SessionType = protocol.Args.SessionType.DH_SHA256; - op.Channel.Send(renegotiateResponse).Send(); + op.Channel.Send(renegotiateResponse); }); coordinator.Run(); } diff --git a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs index 1bfeaa9..18721b6 100644 --- a/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/AuthenticationTests.cs @@ -81,7 +81,7 @@ namespace DotNetOpenAuth.Test.OpenId { request.ClaimedIdentifier = "http://claimedid"; request.LocalIdentifier = "http://localid"; request.ReturnTo = RPUri; - rp.Channel.Send(request).Send(); + rp.Channel.Send(request); if (positive) { if (tamper) { try { @@ -130,20 +130,20 @@ namespace DotNetOpenAuth.Test.OpenId { } else { response = new NegativeAssertionResponse(request) { UserSetupUrl = userSetupUrl }; } - op.Channel.Send(response).Send(); + op.Channel.Send(response); if (positive && !sharedAssociation) { var checkauthRequest = op.Channel.ReadFromRequest<CheckAuthenticationRequest>(); var checkauthResponse = new CheckAuthenticationResponse(checkauthRequest); checkauthResponse.IsValid = checkauthRequest.IsValid; - op.Channel.Send(checkauthResponse).Send(); + op.Channel.Send(checkauthResponse); if (!tamper) { // Respond to the replay attack. checkauthRequest = op.Channel.ReadFromRequest<CheckAuthenticationRequest>(); checkauthResponse = new CheckAuthenticationResponse(checkauthRequest); checkauthResponse.IsValid = checkauthRequest.IsValid; - op.Channel.Send(checkauthResponse).Send(); + op.Channel.Send(checkauthResponse); } } }); diff --git a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs index a9217eb..4f2c574 100644 --- a/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/ChannelElements/ExtensionsBindingElementTests.cs @@ -94,7 +94,7 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { Protocol protocol = Protocol.Default; var op = this.CreateProvider(); IndirectSignedResponse response = CreateResponseWithExtensions(protocol); - op.Channel.Send(response); + op.Channel.PrepareResponse(response); ITamperResistantOpenIdMessage signedResponse = (ITamperResistantOpenIdMessage)response; string extensionAliasKey = signedResponse.ExtraData.Single(kv => kv.Value == MockOpenIdExtension.MockTypeUri).Key; Assert.IsTrue(extensionAliasKey.StartsWith("openid.ns.")); @@ -124,10 +124,10 @@ namespace DotNetOpenAuth.Test.OpenId.ChannelElements { }, op => { RegisterMockExtension(op.Channel); - op.Channel.Send(CreateResponseWithExtensions(protocol)).Send(); + op.Channel.Send(CreateResponseWithExtensions(protocol)); op.GetRequest().Response.Send(); // check_auth op.SecuritySettings.SignOutgoingExtensions = false; - op.Channel.Send(CreateResponseWithExtensions(protocol)).Send(); + op.Channel.Send(CreateResponseWithExtensions(protocol)); op.GetRequest().Response.Send(); // check_auth } ); diff --git a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs index aee9f30..e2ff245 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Extensions/ExtensionTestUtilities.cs @@ -47,7 +47,7 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions { requestBase.Extensions.Add(extension); } - rp.Channel.Send(requestBase).Send(); + rp.Channel.Send(requestBase); var response = rp.Channel.ReadFromRequest<PositiveAssertionResponse>(); var receivedResponses = response.Extensions.Cast<IOpenIdMessageExtension>(); @@ -65,7 +65,7 @@ namespace DotNetOpenAuth.Test.OpenId.Extensions { response.Extensions.Add(extensionResponse); } - op.Channel.Send(response).Send(); + op.Channel.Send(response); }); coordinator.Run(); } diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs index ec6ef9e..7a1824f 100644 --- a/src/DotNetOpenAuth/Messaging/Channel.cs +++ b/src/DotNetOpenAuth/Messaging/Channel.cs @@ -138,15 +138,28 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> - /// Queues an indirect message (either a request or response) + /// Sends an indirect message (either a request or response) + /// or direct message response for transmission to a remote party + /// and ends execution on the current page or handler. + /// </summary> + /// <param name="message">The one-way message to send</param> + /// <exception cref="ThreadAbortException">Thrown by ASP.NET in order to prevent additional data from the page being sent to the client and corrupting the response.</exception> + /// <remarks> + /// Requires an HttpContext.Current context. + /// </remarks> + public void Send(IProtocolMessage message) { + PrepareResponse(message).Send(); + } + + /// <summary> + /// Prepares an indirect message (either a request or response) /// or direct message response for transmission to a remote party. /// </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> - public UserAgentResponse Send(IProtocolMessage message) { - if (message == null) { - throw new ArgumentNullException("message"); - } + public UserAgentResponse PrepareResponse(IProtocolMessage message) { + ErrorUtilities.VerifyArgumentNotNull(message, "message"); + this.PrepareMessageForSending(message); Logger.DebugFormat("Sending message: {0}", message); diff --git a/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs b/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs index 6ae1839..88233ba 100644 --- a/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs +++ b/src/DotNetOpenAuth/Messaging/UserAgentResponse.cs @@ -133,9 +133,13 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> - /// Automatically sends the appropriate response to the user agent. - /// Requires a current HttpContext. + /// Automatically sends the appropriate response to the user agent + /// and ends execution on the current page or handler. /// </summary> + /// <exception cref="ThreadAbortException">Thrown by ASP.NET in order to prevent additional data from the page being sent to the client and corrupting the response.</exception> + /// <remarks> + /// Requires a current HttpContext. + /// </remarks> public virtual void Send() { ErrorUtilities.VerifyOperation(HttpContext.Current != null, MessagingStrings.CurrentHttpContextRequired); diff --git a/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs b/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs index 41d5462..5eda18e 100644 --- a/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs +++ b/src/DotNetOpenAuth/OAuth/DesktopConsumer.cs @@ -40,7 +40,7 @@ namespace DotNetOpenAuth.OAuth { [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "2#", Justification = "Two results")] public Uri RequestUserAuthorization(IDictionary<string, string> requestParameters, IDictionary<string, string> redirectParameters, out string requestToken) { var message = this.PrepareRequestUserAuthorization(null, requestParameters, redirectParameters, out requestToken); - UserAgentResponse response = this.Channel.Send(message); + UserAgentResponse response = this.Channel.PrepareResponse(message); return response.DirectUriRequest; } diff --git a/src/DotNetOpenAuth/OpenId/Provider/Request.cs b/src/DotNetOpenAuth/OpenId/Provider/Request.cs index 6344f03..6546e38 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/Request.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/Request.cs @@ -91,7 +91,7 @@ namespace DotNetOpenAuth.OpenId.Provider { } } - this.cachedUserAgentResponse = this.provider.Channel.Send(this.ResponseMessage); + this.cachedUserAgentResponse = this.provider.Channel.PrepareResponse(this.ResponseMessage); } return this.cachedUserAgentResponse; diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs index 5f3490d..624162e 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs @@ -94,7 +94,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// </summary> /// <value></value> public UserAgentResponse RedirectingResponse { - get { return this.RelyingParty.Channel.Send(this.CreateRequestMessage()); } + get { return this.RelyingParty.Channel.PrepareResponse(this.CreateRequestMessage()); } } /// <summary> |