public void GetToken() { //ZCRMRestClient.Initialize(Dictionary.config); //ZohoOAuthClient client = ZohoOAuthClient.GetInstance(); ZohoOAuthClient.Initialize(); ZCRMRestClient.Initialize(null); ZohoOAuthClient client = ZohoOAuthClient.GetInstance(); //ZohoOAuthParams param = new ZohoOAuthParams(); //param.ClientId = "1000.BT8QS94IIA8278417LUKT1DE7XXBFH"; //param.ClientSecret = "e319f52223bc374d77c65ab410587593cf3ae7e20c"; //param.RedirectURL = "https://zohoapis.zoho.com/"; //param.AccessType = "code"; //param.Scopes = "ZohoCRM.modules.all"; ///ZohoOAuthClient client = new ZohoOAuthClient(param); string grantToken = "1000.a25f043b256bcdcab5804a0cec61c684.ba747fb495a81327a9d78b0e2a1d052f"; // ZohoOAuthTokens tokens = client.GenerateAccessToken(grantToken); //string accessToken = tokens.AccessToken; //string refreshToken = tokens.RefreshToken; try { var conn = client.GetZohoConnector(ZohoOAuth.GetTokenURL()); conn.AddParam(ZohoOAuthConstants.GRANT_TYPE, ZohoOAuthConstants.GRANT_TYPE_AUTH_CODE); conn.AddParam(ZohoOAuthConstants.CODE, grantToken); string response = conn.Post(); string v = string.Empty; JObject responseJSON = JObject.Parse(response); //if (responseJSON.ContainsKey(ZohoOAuthConstants.ACCESS_TOKEN)) //{ // ZohoOAuthTokens tokens = client.GetTokensFromJSON(responseJSON); // tokens.UserMaiilId = client.GetUserMailId(tokens.AccessToken); // ZohoOAuth.GetPersistenceHandlerInstance().SaveOAuthTokens(tokens); // string accessToken = tokens.AccessToken; // string refreshToken = tokens.RefreshToken; // //return tokens; //} //throw new ZohoOAuthException("Exception while fetching Access Token from grant token" + response); } catch (WebException e) { ZCRMLogger.LogError(e); throw new ZohoOAuthException(e); } }
public static string GetAccessToken() { string userMailId = ZCRMRestClient.GetCurrentUserEmail(); if ((userMailId == null) && (!(ConfigProperties.ContainsKey("currentUserEmail")) || (ConfigProperties["currentUserEmail"] == null))) { throw new ZCRMException("Current user must be either set in ZCRMRestClient or zcrm_configuration section in zoho_configuration.config"); } if (userMailId == null) { userMailId = ConfigProperties["currentUserEmail"]; } ZohoOAuthClient client = ZohoOAuthClient.GetInstance(); return(client.GetAccessToken(userMailId)); }
public static ZohoOAuthClient GetInstance(ZohoOAuthParams oAuthParams) { client = new ZohoOAuthClient(oAuthParams); return(client); }
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); } }