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); } }
//Adds Configuration key value pairs specified by the argument to configProperties; private static void AddConfigurationData(string configFileName) { Dictionary <string, string> keyValuePairs = ZohoOAuthUtil.ConfigFileSectionToDict(configFileName); foreach (KeyValuePair <string, string> keyValues in keyValuePairs) { configProperties.Add(keyValues.Key, keyValues.Value); } }
private static void AddConfigurationData(string sectionName) { Dictionary <string, string> keyValuePairs = ZohoOAuthUtil.GetConfigFileAsDict(sectionName); foreach (KeyValuePair <string, string> configData in keyValuePairs) { if (OAUTH_CONFIG_KEYS.Contains(configData.Key)) { ConfigProperties[configData.Key] = configData.Value; } } }
//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); } }
public ZohoOAuthTokens GetOAuthTokens(string userMailId) { ZohoOAuthTokens tokens = new ZohoOAuthTokens(); Dictionary <string, string> oauthTokens = ZohoOAuthUtil.ConfigFileSectionToDict("oauthtokens"); if (!oauthTokens["useridentifier"].Equals(userMailId)) { //TODO: Throw ZohoOAuthException and remove the console write statement; Console.WriteLine("Given user not found in persistence"); } tokens.UserMaiilId = oauthTokens["useridentifier"]; tokens.AccessToken = oauthTokens["accesstoken"]; tokens.RefreshToken = oauthTokens["refreshtoken"]; tokens.ExpiryTime = Convert.ToInt64(oauthTokens["expirytime"]); //TODO: Log the exceptions and implement try catching statements return(tokens); }