//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth.ChannelElements {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
///
/// The messaging channel for OAuth 1.0(a) Consumers.
///
internal class OAuthConsumerChannel : OAuthChannel {
///
/// Initializes a new instance of the class.
///
/// The binding element to use for signing.
/// The web application store to use for nonces.
/// The token manager instance to use.
/// The security settings.
/// The message factory.
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Diagnostics.Contracts.__ContractsRuntime.Requires(System.Boolean,System.String,System.String)", Justification = "Code contracts"), SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "securitySettings", Justification = "Code contracts")]
internal OAuthConsumerChannel(ITamperProtectionChannelBindingElement signingBindingElement, INonceStore store, IConsumerTokenManager tokenManager, ConsumerSecuritySettings securitySettings, IMessageFactory messageFactory = null)
: base(
signingBindingElement,
store,
tokenManager,
securitySettings,
messageFactory ?? new OAuthConsumerMessageFactory(),
InitializeBindingElements(signingBindingElement, store, tokenManager, securitySettings)) {
Contract.Requires(tokenManager != null);
Contract.Requires(securitySettings != null);
Contract.Requires(signingBindingElement != null);
Contract.Requires(signingBindingElement.SignatureCallback == null, OAuthStrings.SigningElementAlreadyAssociatedWithChannel);
}
///
/// Gets the consumer secret for a given consumer key.
///
/// The consumer key.
/// The consumer secret.
protected override string GetConsumerSecret(string consumerKey) {
var consumerTokenManager = (IConsumerTokenManager)this.TokenManager;
ErrorUtilities.VerifyInternal(consumerKey == consumerTokenManager.ConsumerKey, "The token manager consumer key and the consumer key set earlier do not match!");
return consumerTokenManager.ConsumerSecret;
}
///
/// Initializes the binding elements for the OAuth channel.
///
/// The signing binding element.
/// The nonce store.
/// The token manager.
/// The security settings.
///
/// An array of binding elements used to initialize the channel.
///
private static new IChannelBindingElement[] InitializeBindingElements(ITamperProtectionChannelBindingElement signingBindingElement, INonceStore store, ITokenManager tokenManager, SecuritySettings securitySettings) {
Contract.Requires(securitySettings != null);
return OAuthChannel.InitializeBindingElements(signingBindingElement, store, tokenManager, securitySettings).ToArray();
}
}
}