public ZohoOAuthTokens GetOAuthTokens(string userMailId)
        {
            ZohoOAuthTokens tokens;

            try
            {
                tokens = new ZohoOAuthTokens();
                Dictionary <string, string> oauthTokens = ZohoOAuthUtil.GetFileAsDict(new FileStream(GetPersistenceHandlerFilePath(), FileMode.Open));
                //Dictionary<string, string> oauthTokens = ZohoOAuthUtil.ConfigFileSectionToDict("tokens", "oauth_tokens.config");
                if (!oauthTokens["useridentifier"].Equals(userMailId))
                {
                    throw new ZohoOAuthException("Given User not found in configuration");
                }
                tokens.UserMaiilId  = oauthTokens["useridentifier"];
                tokens.AccessToken  = oauthTokens["accesstoken"];
                tokens.RefreshToken = oauthTokens["refreshtoken"];
                tokens.ExpiryTime   = Convert.ToInt64(oauthTokens["expirytime"]);
                return(tokens);
            }
            catch (FileNotFoundException e)
            {
                ZCRMLogger.LogError("Exception while fetching tokens from configuration." + e);
                throw new ZohoOAuthException(e);
            }
        }
Exemplo n.º 2
0
        //Adds Configuration key value pairs specified by the argument to configProperties;
        private static void AddConfigurationData(Stream inputStream)
        {
            Dictionary <string, string> keyValuePairs;

            keyValuePairs = ZohoOAuthUtil.GetFileAsDict(inputStream);
            foreach (KeyValuePair <string, string> keyValues in keyValuePairs)
            {
                if (OAUTH_CONFIG_KEYS.Contains(keyValues.Key))
                {
                    ConfigProperties[keyValues.Key] = keyValues.Value;
                }
            }
        }
        public void DeleteOAuthTokens(string userMailId)
        {
            try
            {
                string persistencePath = GetPersistenceHandlerFilePath();
                Dictionary <string, string> oauthTokens = ZohoOAuthUtil.GetFileAsDict(new FileStream(persistencePath, FileMode.Open));
                if (!oauthTokens["useridentifier"].Equals(userMailId))
                {
                    throw new ZohoOAuthException("Given User not found in configuration");
                }

                File.WriteAllText(persistencePath, String.Empty);
            }
            catch (FileNotFoundException e)
            {
                ZCRMLogger.LogError("Exception while deleting tokens from file." + e);
                throw new ZohoOAuthException(e);
            }
        }