//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOAuth.ChannelElements {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetOAuth.Messaging;
///
/// Sets the HTTP Method property on a signed message before the signing module gets to it.
///
internal class OAuthHttpMethodBindingElement : IChannelBindingElement {
#region IChannelBindingElement Members
///
/// Gets the protection offered (if any) by this binding element.
///
public MessageProtection Protection {
get { return MessageProtection.None; }
}
///
/// Prepares a message for sending based on the rules of this channel binding element.
///
/// The message to prepare for sending.
///
/// True if the applied to this binding element
/// and the operation was successful. False otherwise.
///
public bool PrepareMessageForSending(IProtocolMessage message) {
var oauthMessage = message as ITamperResistantOAuthMessage;
if (oauthMessage != null) {
HttpDeliveryMethod transmissionMethod = oauthMessage.HttpMethods;
if ((transmissionMethod & HttpDeliveryMethod.AuthorizationHeaderRequest) != 0) {
oauthMessage.HttpMethod = "GET";
} else if ((transmissionMethod & HttpDeliveryMethod.PostRequest) != 0) {
oauthMessage.HttpMethod = "POST";
} else if ((transmissionMethod & HttpDeliveryMethod.GetRequest) != 0) {
oauthMessage.HttpMethod = "GET";
} else {
return false;
}
return true;
} else {
return false;
}
}
///
/// Performs any transformation on an incoming message that may be necessary and/or
/// validates an incoming message based on the rules of this channel binding element.
///
/// The incoming message to process.
///
/// True if the applied to this binding element
/// and the operation was successful. False if the operation did not apply to this message.
///
///
/// Thrown when the binding element rules indicate that this message is invalid and should
/// NOT be processed.
///
public bool PrepareMessageForReceiving(IProtocolMessage message) {
return false;
}
#endregion
}
}