summaryrefslogtreecommitdiffstats
path: root/samples/Consumer/App_Code/InMemoryTokenManager.cs
blob: dc80da1899fcfe8a1041d07945bf31c86dbd02c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//-----------------------------------------------------------------------
// <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> tokensAndSecrets = new Dictionary<string, string>();

	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(string consumerKey, string requestToken, string requestTokenSecret, IDictionary<string, string> parameters) {
		this.tokensAndSecrets[requestToken] = requestTokenSecret;
	}

	/// <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
}