Example #1
0
        public static void Initialize(string domainSuffix, Dictionary <string, string> configData)
        {
            try
            {
                if (configData == null)
                {
                    AddConfigurationData("oauth_configuration");
                }
                else
                {
                    AddConfigurationData(configData);
                }

                List <string> MandatoryKeys = new List <string>()
                {
                    ZohoOAuthConstants.CLIENT_ID, ZohoOAuthConstants.CLIENT_SECRET, ZohoOAuthConstants.PERSISTENCE_HANDLER_CLASS, ZohoOAuthConstants.REDIRECT_URL
                };
                foreach (string key in MandatoryKeys)
                {
                    if (ConfigProperties.ContainsKey(key))
                    {
                        if (string.IsNullOrEmpty(ConfigProperties[key]) || string.IsNullOrWhiteSpace(ConfigProperties[key]))
                        {
                            throw new ZCRMException(key + " value is not set");
                        }
                    }
                    else
                    {
                        throw new ZCRMException(key + " is Mandatory");
                    }
                }
                //set iamURL from ConfigProperties
                if (ConfigProperties.ContainsKey(ZohoOAuthConstants.IAM_URL))
                {
                    if (string.IsNullOrEmpty(ConfigProperties[ZohoOAuthConstants.IAM_URL]) || string.IsNullOrWhiteSpace(ConfigProperties[ZohoOAuthConstants.IAM_URL]))
                    {
                        SetIAMUrl(domainSuffix);
                    }
                }
                else
                {
                    SetIAMUrl(domainSuffix);
                }
                ZohoOAuthParams oAuthParams = new ZohoOAuthParams()
                {
                    ClientId     = GetConfigValue(ZohoOAuthConstants.CLIENT_ID),
                    ClientSecret = GetConfigValue(ZohoOAuthConstants.CLIENT_SECRET),
                    AccessType   = GetConfigValue(ZohoOAuthConstants.ACCESS_TYPE) ?? "offline",
                    RedirectURL  = GetConfigValue(ZohoOAuthConstants.REDIRECT_URL)
                };

                ZohoOAuthClient.GetInstance(oAuthParams);
                ZCRMLogger.LogInfo("Zoho OAuth Client Library configuration properties: " + CommonUtil.DictToString(ConfigProperties));
            }
            catch (KeyNotFoundException e)
            {
                ZCRMLogger.LogError("Exception while initializing Zoho OAuth Client .. Essential configuration data not found");
                throw new ZohoOAuthException(e);
            }
        }
Example #2
0
 public static ZohoOAuthClient GetInstance(ZohoOAuthParams oAuthParams)
 {
     client = new ZohoOAuthClient(oAuthParams);
     return(client);
 }