diff options
author | David Christiansen <coding@davedoes.net> | 2012-06-30 16:06:46 -0700 |
---|---|---|
committer | David Christiansen <coding@davedoes.net> | 2012-06-30 16:06:46 -0700 |
commit | 06401bb049dc29cf4446eb61a4a72317a644ce54 (patch) | |
tree | 7c475929350b31b4b848a1faa57bd0d7cbbf512c /src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs | |
parent | 02ce959db12fec57e846e5ebfa662cd0327ce69c (diff) | |
parent | 3286c37f3a967e7d142534df84604a66be9d176c (diff) | |
download | DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.zip DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.gz DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.bz2 |
Merge pull request #1 from DavidChristiansen/master
Kachow!
Diffstat (limited to 'src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs')
-rw-r--r-- | src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs b/src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs new file mode 100644 index 0000000..0dad973 --- /dev/null +++ b/src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs @@ -0,0 +1,49 @@ +//----------------------------------------------------------------------- +// <copyright file="InMemoryClientAuthorizationTracker.cs" company="Outercurve Foundation"> +// Copyright (c) Outercurve Foundation. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.ServiceModel; + using System.Text; + using System.Threading; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OAuth2; + + internal class InMemoryClientAuthorizationTracker : IClientAuthorizationTracker { + private readonly Dictionary<int, IAuthorizationState> savedStates = new Dictionary<int, IAuthorizationState>(); + private int stateCounter; + + #region Implementation of IClientTokenManager + + /// <summary> + /// Gets the state of the authorization for a given callback URL and client state. + /// </summary> + /// <param name="callbackUrl">The callback URL.</param> + /// <param name="clientState">State of the client stored at the beginning of an authorization request.</param> + /// <returns>The authorization state; may be <c>null</c> if no authorization state matches.</returns> + public IAuthorizationState GetAuthorizationState(Uri callbackUrl, string clientState) { + IAuthorizationState state; + if (this.savedStates.TryGetValue(int.Parse(clientState), out state)) { + if (state.Callback != callbackUrl) { + throw new DotNetOpenAuth.Messaging.ProtocolException("Client state and callback URL do not match."); + } + } + + return state; + } + + #endregion + + internal IAuthorizationState NewAuthorization(HashSet<string> scope, out string clientState) { + int counter = Interlocked.Increment(ref this.stateCounter); + clientState = counter.ToString(CultureInfo.InvariantCulture); + return this.savedStates[counter] = new AuthorizationState(scope); + } + } +} |