示例#1
0
 //TODO: Create ZohoOAuthException class and change the throw exception class;
 public ZohoOAuthTokens RefreshAccessToken(string refreshToken, string userMailId)
 {
     if (refreshToken == null)
     {
         throw new ZohoOAuthException("Refresh token is not provided");
     }
     try
     {
         ZohoHTTPConnector conn = GetZohoConnector(ZohoOAuth.GetRefreshTokenURL());
         conn.AddParam(ZohoOAuthConstants.GRANT_TYPE, ZohoOAuthConstants.REFRESH_TOKEN);
         conn.AddParam(ZohoOAuthConstants.REFRESH_TOKEN, refreshToken);
         string  response     = conn.Post();
         JObject responseJSON = JObject.Parse(response);
         if (responseJSON.ContainsKey(ZohoOAuthConstants.ACCESS_TOKEN))
         {
             ZohoOAuthTokens tokens = GetTokensFromJSON(responseJSON);
             tokens.RefreshToken = refreshToken;
             tokens.UserMaiilId  = userMailId;
             ZohoOAuth.GetPersistenceHandlerInstance().SaveOAuthTokens(tokens);
             return(tokens);
         }
         throw new ZohoOAuthException("Exception while fetching access tokens from Refresh Token" + response);
     }
     catch (WebException e)
     {
         ZCRMLogger.LogError(e);
         throw new ZohoOAuthException(e);
     }
 }
示例#2
0
        public ZohoHTTPConnector GetZohoConnector(string url)
        {
            ZohoHTTPConnector conn = new ZohoHTTPConnector()
            {
                Url = url
            };

            conn.AddParam(ZohoOAuthConstants.CLIENT_ID, oAuthParams.ClientId);
            conn.AddParam(ZohoOAuthConstants.CLIENT_SECRET, oAuthParams.ClientSecret);
            conn.AddParam(ZohoOAuthConstants.REDIRECT_URL, oAuthParams.RedirectURL);
            return(conn);
        }