コード例 #1
0
        //TODO: Create ZohoOAuthException class and change the throw exception class;
        private ZohoOAuthTokens RefreshAccessToken(string refreshToken, string userMailId)
        {
            if (refreshToken == null)
            {
                throw new Exception("Refresh token is not provided");
            }

            try{
                ZohoHTTPConnector conn = GetZohoConnector(ZohoOAuth.GetRefreshTokenURL());
                conn.AddParam("grant_type", "refresh_token");
                conn.AddParam("refresh_token", refreshToken);
                string response = conn.Post();
                Dictionary <string, string> responseJson = JsonConvert.DeserializeObject <Dictionary <string, string> >(response);
                if (responseJson.ContainsKey("access_token"))
                {
                    ZohoOAuthTokens tokens = GetTokensFromJSON(responseJson);
                    tokens.RefreshToken = refreshToken;
                    tokens.UserMaiilId  = userMailId;
                    ZohoOAuth.GetPersistenceHandlerInstance().SaveOAuthData(tokens);
                    return(tokens);
                }

                throw new Exception("Exception while fetching access tokens from site");
            }catch (Exception e) {
                Console.WriteLine(e.Message);
                throw;
            }
        }
コード例 #2
0
 //TODO: Create ZohoOAuthException class and change the throw exception class;
 private 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);
     }
 }