/// <summary> /// Prepares to send a request to the Service Provider as the query string in a GET request. /// </summary> /// <param name="requestMessage">The message to be transmitted to the ServiceProvider.</param> /// <returns>The web request ready to send.</returns> /// <remarks> /// This method is simply a standard HTTP Get request with the message parts serialized to the query string. /// This method satisfies OAuth 1.0 section 5.2, item #3. /// </remarks> protected virtual HttpWebRequest InitializeRequestAsGet(IDirectedProtocolMessage requestMessage) { ErrorUtilities.VerifyArgumentNotNull(requestMessage, "requestMessage"); var serializer = MessageSerializer.Get(requestMessage.GetType()); var fields = serializer.Serialize(requestMessage); UriBuilder builder = new UriBuilder(requestMessage.Recipient); MessagingUtilities.AppendQueryArgs(builder, fields); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(builder.Uri); return(httpRequest); }
/// <summary> /// Queues an indirect message for transmittal via the user agent. /// </summary> /// <param name="message">The message to send.</param> /// <returns>The pending user agent redirect based message to be sent as an HttpResponse.</returns> protected virtual UserAgentResponse SendIndirectMessage(IDirectedProtocolMessage message) { ErrorUtilities.VerifyArgumentNotNull(message, "message"); var serializer = MessageSerializer.Get(message.GetType()); var fields = serializer.Serialize(message); // First try creating a 301 redirect, and fallback to a form POST // if the message is too big. UserAgentResponse response = this.Create301RedirectResponse(message, fields); if (response.Headers[HttpResponseHeader.Location].Length > indirectMessageGetToPostThreshold) { response = this.CreateFormPostResponse(message, fields); } return(response); }
/// <summary> /// Deserializes a dictionary of values into a message. /// </summary> /// <param name="fields">The dictionary of values that were read from an HTTP request or response.</param> /// <param name="recipient">Information about where the message was been directed. Null for direct response messages.</param> /// <returns>The deserialized message, or null if no message could be recognized in the provided data.</returns> protected virtual IProtocolMessage Receive(Dictionary <string, string> fields, MessageReceivingEndpoint recipient) { ErrorUtilities.VerifyArgumentNotNull(fields, "fields"); IProtocolMessage message = this.MessageFactory.GetNewRequestMessage(recipient, fields); // If there was no data, or we couldn't recognize it as a message, abort. if (message == null) { return(null); } // We have a message! Assemble it. var serializer = MessageSerializer.Get(message.GetType()); serializer.Deserialize(fields, message); return(message); }