public void Logout(IOAuthClientConfiguration configuration)
 {
     configuration.SetAuthorizationCookie(string.Empty);
 }
        public void UserLoggedIn(IOAuthClientConfiguration configuration, string authorizationCode, NameValueCollection state)
        {
            var user = GetUserByAuthorizationCode(configuration, authorizationCode);
            if (user != null)
            {
                user.SynchronizedUserName = state[Constants.SynchronizedUserNameQueryStringKey];
                configuration.SetAuthorizationCookie(user.Serialize(configuration.OAuthClientSecret));
            }

            configuration.UserLoggedIn(state);
        }
        public User GetUser(IOAuthClientConfiguration configuration, NameValueCollection state, Action<Uri> redirect)
        {
            var user = GetCurrentUser(configuration);
            var syncClient = configuration as IUserSynchronizedOAuthClientConfiguration;
            var createClient = configuration as IUserCreatableOAuthClientConfiguration;

            if(createClient != null)
                user = ValidateAgainstLocalUser(createClient, user, state, redirect);

            if(syncClient != null)
                user = ValidateAgainstUserSynchronization(configuration as IUserSynchronizedOAuthClientConfiguration, user, state, redirect);

            if (user != null && user.TokenExpiresUtc.Subtract(DateTime.UtcNow).TotalMinutes < Constants.RefreshMarginMinutes)
                user = RefreshOAuthToken(configuration, user);

            if (user != null && string.CompareOrdinal(user.UserName, configuration.DefaultUserName) != 0)
                configuration.SetAuthorizationCookie(user.Serialize(configuration.OAuthClientSecret));
            else
                configuration.SetAuthorizationCookie(string.Empty);

            return user;
        }