//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- 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 savedStates = new Dictionary(); private int stateCounter; #region Implementation of IClientTokenManager /// /// Gets the state of the authorization for a given callback URL and client state. /// /// The callback URL. /// State of the client stored at the beginning of an authorization request. /// The authorization state; may be null if no authorization state matches. 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 scope, out string clientState) { int counter = Interlocked.Increment(ref this.stateCounter); clientState = counter.ToString(CultureInfo.InvariantCulture); return this.savedStates[counter] = new AuthorizationState(scope); } } #endif }