Exemplo n.º 1
0
        /// <summary>
        /// Gets an available access token for a particulare store.  This is probably a method you shouldn't be using in production code,
        /// as it will likely result in using the wrong/inappropriate token to peform operations.
        /// </summary>
        /// <param name="storeType">Type off store</param>
        /// <returns>Access token for the store.</returns>
        public String GetAnyAccessToken(TokenStoreType storeType)
        {
            TokenStore entities = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = entities.Tokens.Where(t => t.Type == (int)TokenType.AccessToken & t.StoreTypeId == (int)storeType);

            foreach (var tokenItem in tokens)
            {
                return tokenItem.TokenContent;
            }

            return null;
        }
        public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, TokenStoreType storeType, String userId, string accessToken, string accessTokenSecret)
        {
            TokenStore entities = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = entities.Tokens.Where(t => t.TokenContent == requestToken & t.StoreTypeId == (int)storeType);

            foreach (var tokenItem in tokens)
            {
                entities.DeleteObject(tokenItem);
            }

            tokens = entities.Tokens.Where(t => t.TokenContent == accessToken & t.StoreTypeId == (int)storeType);
            bool doSaveChanges = false;

            foreach (var tokenItem in tokens)
            {
                tokenItem.Secret = accessTokenSecret;
                tokenItem.UserId = userId;

                doSaveChanges = true;
            }

            if (doSaveChanges)
            {
                entities.SaveChanges();
                return;
            }

            // go create a new token.
            Token tas = entities.Tokens.CreateObject();
            tas.Id = Guid.NewGuid();
            tas.UserId = userId;
            tas.TokenContent = accessToken;
            tas.Secret = accessTokenSecret;
            tas.StoreTypeId = (byte)storeType;
            tas.Type = (int)TokenType.AccessToken;

            entities.Tokens.AddObject(tas);
            entities.SaveChanges();

            this.localTokensAndSecrets.Remove(requestToken);
            this.localTokensAndSecrets[accessToken] = accessTokenSecret;
        }
Exemplo n.º 3
0
        public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, TokenStoreType storeType, String userId, string accessToken, string accessTokenSecret) 
        {
            TokenStore entities = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = entities.Tokens.Where(t => t.TokenContent == requestToken & t.StoreTypeId == (int)storeType);

            foreach (var tokenItem in tokens)
            {
                entities.DeleteObject(tokenItem);
            }

            tokens = entities.Tokens.Where(t => t.TokenContent == accessToken & t.StoreTypeId == (int)storeType);
            bool doSaveChanges = false;

            foreach (var tokenItem in tokens)
            {
                tokenItem.Secret = accessTokenSecret;
                tokenItem.UserId = userId;

                doSaveChanges = true;
            }

            if (doSaveChanges)
            {
                entities.SaveChanges();
                return;
            }

            // go create a new token.
            Token tas = entities.Tokens.CreateObject();
            tas.Id = Guid.NewGuid();
            tas.UserId = userId;
            tas.TokenContent = accessToken;
            tas.Secret = accessTokenSecret;
            tas.StoreTypeId = (byte)storeType;
            tas.Type = (int)TokenType.AccessToken;

            entities.Tokens.AddObject(tas);
            entities.SaveChanges();

            this.localTokensAndSecrets.Remove(requestToken);
            this.localTokensAndSecrets[accessToken] = accessTokenSecret;
		}
Exemplo n.º 4
0
        public bool GetAccessTokenAndSecret(TokenStoreType storeType, String userId, out String accessToken, out String accessTokenSecret)
        {
            TokenStore entities = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = entities.Tokens.Where(t => t.UserId == userId & t.Type == (int)TokenType.AccessToken & t.StoreTypeId == (int)storeType);

            foreach (var tokenItem in tokens)
            {
                accessToken = tokenItem.TokenContent;
                accessTokenSecret = tokenItem.Secret;

                return true;
            }

            accessToken = null;
            accessTokenSecret = null;

            return false;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieves a token secret given an original token.
        /// </summary>
        /// <param name="storeType">Type of store to connect to.</param>
        /// <param name="token">Content of token to match against.</param>
        /// <returns></returns>
        public string GetTokenSecret(TokenStoreType storeType, string token) 
        {
            if (this.localTokensAndSecrets.ContainsKey(token))
            {
                return this.localTokensAndSecrets[token];
            }

            TokenStore ts = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = ts.Tokens.Where(t => t.TokenContent == token & t.StoreTypeId == (int)storeType);

            // should probably do better enforcement here that there is only one response.
            foreach (var tokenItem in tokens)
            {
                this.localTokensAndSecrets[token] = tokenItem.Secret;

                return tokenItem.Secret;
            } 
            
            return null;
		}
Exemplo n.º 6
0
        public void StoreNewToken(TokenType tokenType, TokenStoreType storeType, String userId, String token, String contextContent, String tokenSecret)
        {
			this.localTokensAndSecrets[token] = tokenSecret;

            // does the token already exist?
            TokenStore tokenStore = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = tokenStore.Tokens.Where(t => t.TokenContent == token & t.StoreTypeId == (byte)storeType & t.UserId == userId & t.Type == (int)TokenType.AccessToken);
            bool doSaveChanges = false;

            foreach (var tokenItem in tokens)
            {
                tokenItem.Secret = tokenSecret;
                tokenItem.UserId = userId;
                tokenItem.StoreTypeId = (byte)storeType;
                tokenItem.ContextContent = contextContent;
                doSaveChanges = true; 
            }

            if (doSaveChanges)
            {
                tokenStore.SaveChanges();
                return;
            }

            // go create a new token.
            Token tas = tokenStore.Tokens.CreateObject();
            tas.Id = Guid.NewGuid();
            tas.UserId =  userId;
            tas.TokenContent = token;
            tas.Secret = tokenSecret;
            tas.StoreTypeId = (byte)storeType;
            tas.ContextContent = contextContent;
            tas.Type = (int)tokenType;

            tokenStore.Tokens.AddObject(tas);
            tokenStore.SaveChanges();
        }
        public void StoreNewToken(TokenType tokenType, TokenStoreType storeType, String userId, String token, String contextContent, String tokenSecret)
        {
            this.localTokensAndSecrets[token] = tokenSecret;

            // does the token already exist?
            TokenStore tokenStore = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = tokenStore.Tokens.Where(t => t.TokenContent == token & t.StoreTypeId == (byte)storeType & t.UserId == userId & t.Type == (int)TokenType.AccessToken);
            bool doSaveChanges = false;

            foreach (var tokenItem in tokens)
            {
                tokenItem.Secret = tokenSecret;
                tokenItem.UserId = userId;
                tokenItem.StoreTypeId = (byte)storeType;
                tokenItem.ContextContent = contextContent;
                doSaveChanges = true;
            }

            if (doSaveChanges)
            {
                tokenStore.SaveChanges();
                return;
            }

            // go create a new token.
            Token tas = tokenStore.Tokens.CreateObject();
            tas.Id = Guid.NewGuid();
            tas.UserId =  userId;
            tas.TokenContent = token;
            tas.Secret = tokenSecret;
            tas.StoreTypeId = (byte)storeType;
            tas.ContextContent = contextContent;
            tas.Type = (int)tokenType;

            tokenStore.Tokens.AddObject(tas);
            tokenStore.SaveChanges();
        }
        /// <summary>
        /// Retrieves a token secret given an original token.
        /// </summary>
        /// <param name="storeType">Type of store to connect to.</param>
        /// <param name="token">Content of token to match against.</param>
        /// <returns></returns>
        public string GetTokenSecret(TokenStoreType storeType, string token)
        {
            if (this.localTokensAndSecrets.ContainsKey(token))
            {
                return this.localTokensAndSecrets[token];
            }

            TokenStore ts = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = ts.Tokens.Where(t => t.TokenContent == token & t.StoreTypeId == (int)storeType);

            // should probably do better enforcement here that there is only one response.
            foreach (var tokenItem in tokens)
            {
                this.localTokensAndSecrets[token] = tokenItem.Secret;

                return tokenItem.Secret;
            }

            return null;
        }
        /// <summary>
        /// Gets an available access token for a particulare store.  This is probably a method you shouldn't be using in production code,
        /// as it will likely result in using the wrong/inappropriate token to peform operations.
        /// </summary>
        /// <param name="storeType">Type off store</param>
        /// <returns>Access token for the store.</returns>
        public String GetAnyAccessToken(TokenStoreType storeType)
        {
            TokenStore entities = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = entities.Tokens.Where(t => t.Type == (int)TokenType.AccessToken & t.StoreTypeId == (int)storeType);

            foreach (var tokenItem in tokens)
            {
                return tokenItem.TokenContent;
            }

            return null;
        }
        public bool GetAccessTokenAndSecret(TokenStoreType storeType, String userId, out String accessToken, out String accessTokenSecret)
        {
            TokenStore entities = new TokenStore(Utilities.GetEntityConnectionString());

            var tokens = entities.Tokens.Where(t => t.UserId == userId & t.Type == (int)TokenType.AccessToken & t.StoreTypeId == (int)storeType);

            foreach (var tokenItem in tokens)
            {
                accessToken = tokenItem.TokenContent;
                accessTokenSecret = tokenItem.Secret;

                return true;
            }

            accessToken = null;
            accessTokenSecret = null;

            return false;
        }