//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.AspNet.Clients {
using System;
using DotNetOpenAuth.OAuth.ChannelElements;
///
/// Simple wrapper around IConsumerTokenManager
///
public class SimpleConsumerTokenManager : IConsumerTokenManager {
///
/// Store the token manager.
///
private readonly IOAuthTokenManager tokenManager;
///
/// Initializes a new instance of the class.
///
/// The consumer key.
/// The consumer secret.
/// The OAuth token manager.
public SimpleConsumerTokenManager(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) {
Requires.NotNullOrEmpty(consumerKey, "consumerKey");
Requires.NotNullOrEmpty(consumerSecret, "consumerSecret");
Requires.NotNull(tokenManager, "oAuthTokenManager");
this.ConsumerKey = consumerKey;
this.ConsumerSecret = consumerSecret;
this.tokenManager = tokenManager;
}
///
/// Gets the consumer key.
///
///
/// The consumer key.
///
public string ConsumerKey {
get;
private set;
}
///
/// Gets the consumer secret.
///
///
/// The consumer secret.
///
public string ConsumerSecret {
get;
private set;
}
///
/// Gets the Token Secret given a request or access token.
///
/// The request or access token.
///
/// The secret associated with the given token.
///
/// Thrown if the secret cannot be found for the given token.
public string GetTokenSecret(string token) {
return this.tokenManager.GetTokenSecret(token);
}
///
/// Stores a newly generated unauthorized request token, secret, and optional
/// application-specific parameters for later recall.
///
/// The request message that resulted in the generation of a new unauthorized request token.
/// The response message that includes the unauthorized request token.
/// Thrown if the consumer key is not registered, or a required parameter was not found in the parameters collection.
public void StoreNewRequestToken(DotNetOpenAuth.OAuth.Messages.UnauthorizedTokenRequest request, DotNetOpenAuth.OAuth.Messages.ITokenSecretContainingMessage response) {
this.tokenManager.StoreRequestToken(response.Token, response.TokenSecret);
}
///
/// Deletes a request token and its associated secret and stores a new access token and secret.
///
/// The Consumer that is exchanging its request token for an access token.
/// The Consumer's request token that should be deleted/expired.
/// The new access token that is being issued to the Consumer.
/// The secret associated with the newly issued access token.
public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
this.tokenManager.ReplaceRequestTokenWithAccessToken(requestToken, accessToken, accessTokenSecret);
}
///
/// Classifies a token as a request token or an access token.
///
/// The token to classify.
///
/// Request or Access token, or invalid if the token is not recognized.
///
public TokenType GetTokenType(string token) {
throw new NotSupportedException();
}
}
}