diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-26 16:01:37 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-26 16:01:37 -0700 |
commit | fc29aefdf4fe9fb1081ee21c01f5ba3963904be6 (patch) | |
tree | 74e1cb88f7a600f446df513a3a15a0104d7ff7e7 /samples/OAuthConsumerWpf/InMemoryTokenManager.cs | |
parent | d18ea6028e8c6cadbf99e2c4529350c26224c6ff (diff) | |
parent | ad95a2e4ab219a246a2288c62452b0d920a7cdc2 (diff) | |
download | DotNetOpenAuth-fc29aefdf4fe9fb1081ee21c01f5ba3963904be6.zip DotNetOpenAuth-fc29aefdf4fe9fb1081ee21c01f5ba3963904be6.tar.gz DotNetOpenAuth-fc29aefdf4fe9fb1081ee21c01f5ba3963904be6.tar.bz2 |
Merge branch 'samplerename'
Diffstat (limited to 'samples/OAuthConsumerWpf/InMemoryTokenManager.cs')
-rw-r--r-- | samples/OAuthConsumerWpf/InMemoryTokenManager.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/samples/OAuthConsumerWpf/InMemoryTokenManager.cs b/samples/OAuthConsumerWpf/InMemoryTokenManager.cs new file mode 100644 index 0000000..b4692f1 --- /dev/null +++ b/samples/OAuthConsumerWpf/InMemoryTokenManager.cs @@ -0,0 +1,72 @@ +//----------------------------------------------------------------------- +// <copyright file="InMemoryTokenManager.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. 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 : ITokenManager { + private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>(); + + internal InMemoryTokenManager() { + } + + internal string ConsumerKey { get; set; } + + internal string ConsumerSecret { get; 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; + } + + /// <summary> + /// Checks whether a given request token has already been authorized + /// by some user for use by the Consumer that requested it. + /// </summary> + /// <param name="requestToken">The Consumer's request token.</param> + /// <returns> + /// 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. + /// </returns> + 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; + } + + /// <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 + } +} |