diff options
Diffstat (limited to 'src/OAuth/OAuthConsumerWpf/InMemoryTokenManager.cs')
-rw-r--r-- | src/OAuth/OAuthConsumerWpf/InMemoryTokenManager.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/OAuth/OAuthConsumerWpf/InMemoryTokenManager.cs b/src/OAuth/OAuthConsumerWpf/InMemoryTokenManager.cs new file mode 100644 index 0000000..5266404 --- /dev/null +++ b/src/OAuth/OAuthConsumerWpf/InMemoryTokenManager.cs @@ -0,0 +1,58 @@ +//----------------------------------------------------------------------- +// <copyright file="InMemoryTokenManager.cs" company="Outercurve Foundation"> +// Copyright (c) Outercurve Foundation. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Samples.OAuthConsumerWpf { + using System; + using System.Collections.Generic; + using System.Diagnostics; + using DotNetOpenAuth.OAuth.ChannelElements; + using DotNetOpenAuth.OAuth.Messages; + + internal class InMemoryTokenManager : IConsumerTokenManager { + private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>(); + + internal InMemoryTokenManager() { + } + + public string ConsumerKey { get; internal set; } + + public string ConsumerSecret { get; internal 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; + } + + public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) { + this.tokensAndSecrets.Remove(requestToken); + this.tokensAndSecrets[accessToken] = accessTokenSecret; + } + + /// <summary> + /// Classifies a token as a request token or an access token. + /// </summary> + /// <param name="token">The token to classify.</param> + /// <returns>Request or Access token, or invalid if the token is not recognized.</returns> + public TokenType GetTokenType(string token) { + throw new NotImplementedException(); + } + + #endregion + } +} |