summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs
diff options
context:
space:
mode:
authorDavid Christiansen <coding@davedoes.net>2012-03-15 22:10:55 +0000
committerDavid Christiansen <coding@davedoes.net>2012-03-15 22:10:55 +0000
commita5bfa2bb8a614b1932ec8b7bbc6a0cc6bca3051f (patch)
treea3057157fa3287e0c0c4cc49be1854f9aa63d321 /src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs
parent02ce959db12fec57e846e5ebfa662cd0327ce69c (diff)
downloadDotNetOpenAuth.Samples-a5bfa2bb8a614b1932ec8b7bbc6a0cc6bca3051f.zip
DotNetOpenAuth.Samples-a5bfa2bb8a614b1932ec8b7bbc6a0cc6bca3051f.tar.gz
DotNetOpenAuth.Samples-a5bfa2bb8a614b1932ec8b7bbc6a0cc6bca3051f.tar.bz2
W.I.P.
* Initial migration and reference to DNOA Nuget packages (From teamcity.dotnetopenauth.net) * Awaiting fix to DotNetOpenAuth.OpenIdOAuth.nuspec in order to complete migration.
Diffstat (limited to 'src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs')
-rw-r--r--src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs b/src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs
new file mode 100644
index 0000000..9662cb2
--- /dev/null
+++ b/src/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs
@@ -0,0 +1,51 @@
+//-----------------------------------------------------------------------
+// <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;
+
+#if SAMPLESONLY
+ 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);
+ }
+ }
+#endif
+}