diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-10-04 16:45:52 -0700 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-10-04 16:45:52 -0700 |
commit | 9ffccf622b5c669027c8cbb9ee2f8735ea25d636 (patch) | |
tree | 5d25daff51635cd05e419d7fe42d25d6e1a3e262 /samples/ServiceProvider/App_Code/InMemoryTokenManager.cs | |
parent | 2e681a4b643fec2cdac42c729cb08ea3faa7a099 (diff) | |
download | DotNetOpenAuth-9ffccf622b5c669027c8cbb9ee2f8735ea25d636.zip DotNetOpenAuth-9ffccf622b5c669027c8cbb9ee2f8735ea25d636.tar.gz DotNetOpenAuth-9ffccf622b5c669027c8cbb9ee2f8735ea25d636.tar.bz2 |
Added WCF sample consumer and service provider.
It's pretty delicate and a poor sample, but hey, it worked.
Diffstat (limited to 'samples/ServiceProvider/App_Code/InMemoryTokenManager.cs')
-rw-r--r-- | samples/ServiceProvider/App_Code/InMemoryTokenManager.cs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/samples/ServiceProvider/App_Code/InMemoryTokenManager.cs b/samples/ServiceProvider/App_Code/InMemoryTokenManager.cs new file mode 100644 index 0000000..540fd81 --- /dev/null +++ b/samples/ServiceProvider/App_Code/InMemoryTokenManager.cs @@ -0,0 +1,91 @@ +//-----------------------------------------------------------------------
+// <copyright file="InMemoryTokenManager.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using DotNetOAuth.ChannelElements;
+
+public class InMemoryTokenManager : ITokenManager {
+ private Dictionary<string, string> consumersAndSecrets = new Dictionary<string, string>();
+ private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
+
+ /// <summary>
+ /// Request tokens that have been issued, and whether they have been authorized yet.
+ /// </summary>
+ private Dictionary<string, bool> requestTokens = new Dictionary<string, bool>();
+
+ /// <summary>
+ /// Access tokens that have been issued and have not yet expired.
+ /// </summary>
+ private List<string> accessTokens = new List<string>();
+
+ #region ITokenManager Members
+
+ public string GetConsumerSecret(string consumerKey) {
+ return this.consumersAndSecrets[consumerKey];
+ }
+
+ public string GetTokenSecret(string token) {
+ return this.tokensAndSecrets[token];
+ }
+
+ public void StoreNewRequestToken(string consumerKey, string requestToken, string requestTokenSecret, IDictionary<string, string> parameters) {
+ this.tokensAndSecrets[requestToken] = requestTokenSecret;
+ this.requestTokens.Add(requestToken, false);
+ }
+
+ /// <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) {
+ return this.requestTokens[requestToken];
+ }
+
+ public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) {
+ Debug.Assert(this.requestTokens[requestToken], "Unauthorized token should not be exchanged for access token.");
+ this.requestTokens.Remove(requestToken);
+ this.accessTokens.Add(accessToken);
+ 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) {
+ if (this.requestTokens.ContainsKey(token)) {
+ return TokenType.RequestToken;
+ } else if (this.accessTokens.Contains(token)) {
+ return TokenType.AccessToken;
+ } else {
+ return TokenType.InvalidToken;
+ }
+ }
+
+ #endregion
+
+ public void AddConsumer(string key, string secret) {
+ this.consumersAndSecrets.Add(key, secret);
+ }
+
+ public void AuthorizeRequestToken(string requestToken) {
+ if (requestToken == null) {
+ throw new ArgumentNullException("requestToken");
+ }
+
+ this.requestTokens[requestToken] = true;
+ }
+}
|