//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
public class InMemoryTokenManager : ITokenManager {
private Dictionary tokensAndSecrets = new Dictionary();
public InMemoryTokenManager(string consumerKey, string consumerSecret) {
this.ConsumerKey = consumerKey;
this.ConsumerSecret = consumerSecret;
}
public string ConsumerKey { get; private set; }
public string ConsumerSecret { get; private set; }
#region ITokenManager Members
public string GetConsumerSecret(string consumerKey) {
if (consumerKey == this.ConsumerKey) {
return this.ConsumerSecret;
} else {
throw new ArgumentException("Unrecognized consumer key.", "consumerKey");
}
}
public string GetTokenSecret(string token) {
return this.tokensAndSecrets[token];
}
public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response) {
this.tokensAndSecrets[response.Token] = response.TokenSecret;
}
///
/// Checks whether a given request token has already been authorized
/// by some user for use by the Consumer that requested it.
///
/// The Consumer's request token.
///
/// True if the request token has already been fully authorized by the user
/// who owns the relevant protected resources. False if the token has not yet
/// been authorized, has expired or does not exist.
///
public bool IsRequestTokenAuthorized(string requestToken) {
throw new NotImplementedException();
}
public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
this.tokensAndSecrets.Remove(requestToken);
this.tokensAndSecrets[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 NotImplementedException();
}
#endregion
}