//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth.ChannelElements {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
using Validation;
///
/// The messaging channel for OAuth 1.0(a) Service Providers.
///
internal class OAuthServiceProviderChannel : 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 type provider.
/// The host factories.
[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 OAuthServiceProviderChannel(ITamperProtectionChannelBindingElement signingBindingElement, INonceStore store, IServiceProviderTokenManager tokenManager, ServiceProviderSecuritySettings securitySettings, IMessageFactory messageTypeProvider = null, IHostFactories hostFactories = null)
: base(
signingBindingElement,
tokenManager,
securitySettings,
messageTypeProvider ?? new OAuthServiceProviderMessageFactory(tokenManager),
InitializeBindingElements(signingBindingElement, store, tokenManager, securitySettings),
hostFactories) {
Requires.NotNull(tokenManager, "tokenManager");
Requires.NotNull(securitySettings, "securitySettings");
Requires.NotNull(signingBindingElement, "signingBindingElement");
}
///
/// Gets the consumer secret for a given consumer key.
///
/// The consumer key.
/// The consumer secret.
protected override string GetConsumerSecret(string consumerKey) {
return ((IServiceProviderTokenManager)this.TokenManager).GetConsumer(consumerKey).Secret;
}
///
/// 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 IChannelBindingElement[] InitializeBindingElements(ITamperProtectionChannelBindingElement signingBindingElement, INonceStore store, ITokenManager tokenManager, SecuritySettings securitySettings) {
Requires.NotNull(securitySettings, "securitySettings");
var bindingElements = OAuthChannel.InitializeBindingElements(signingBindingElement, store);
var spTokenManager = tokenManager as IServiceProviderTokenManager;
var serviceProviderSecuritySettings = securitySettings as ServiceProviderSecuritySettings;
bindingElements.Insert(0, new TokenHandlingBindingElement(spTokenManager, serviceProviderSecuritySettings));
return bindingElements.ToArray();
}
}
}