diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-07-05 07:47:24 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-07-05 07:47:24 -0700 |
commit | 46e4f75e2ea9fb66c6e7a2a32657ad442505b95e (patch) | |
tree | 94a2f7525dfca1f8bd58099cd083581727a52d82 /samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs | |
parent | 5d1f7e810dd7169a75098e80031ae89926581042 (diff) | |
download | DotNetOpenAuth-46e4f75e2ea9fb66c6e7a2a32657ad442505b95e.zip DotNetOpenAuth-46e4f75e2ea9fb66c6e7a2a32657ad442505b95e.tar.gz DotNetOpenAuth-46e4f75e2ea9fb66c6e7a2a32657ad442505b95e.tar.bz2 |
Simplified using the web server client a bit (no "token manager" needed any more).
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs')
-rw-r--r-- | samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs b/samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs new file mode 100644 index 0000000..239b3ac --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/InMemoryClientAuthorizationTracker.cs @@ -0,0 +1,53 @@ +//----------------------------------------------------------------------- +// <copyright file="InMemoryClientAuthorizationTracker.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. 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(string scope, out string clientState) { + int counter = Interlocked.Increment(ref this.stateCounter); + clientState = counter.ToString(CultureInfo.InvariantCulture); + return this.savedStates[counter] = new AuthorizationState { + Scope = scope, + }; + } + } +#endif +} |