//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; } }
//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); } }
private ZohoHTTPConnector GetZohoConnector(string url) { ZohoHTTPConnector conn = new ZohoHTTPConnector() { Url = url }; conn.AddParam("client_id", oAuthParams.ClientId); conn.AddParam("client_secret", oAuthParams.ClientSecret); conn.AddParam("redirect_uri", oAuthParams.RedirectURL); return(conn); }
private 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); }
//TODO: the method throws three exceptions and check for null exception on access_token. private string GetUserMailId(string accessToken) { ZohoHTTPConnector conn = new ZohoHTTPConnector() { Url = ZohoOAuth.GetUserInfoURL() }; conn.AddHeader("Authorization", ZohoOAuthConstants.AuthHeaderPrefix + accessToken); string response = conn.Get(); JObject responseJSON = JObject.Parse(response); return(responseJSON["Email"].ToString()); }
//TODO: the method throws three exceptions and check for null exception on access_token. private string GetUserMailId(string accessToken) { try { ZohoHTTPConnector conn = new ZohoHTTPConnector() { Url = ZohoOAuth.GetUserInfoURL() }; conn.AddHeader("Authorization", ZohoOAuthConstants.AuthHeaderPrefix + accessToken); string response = conn.Get(); JObject responseJSON = JObject.Parse(response); return(responseJSON["Email"].ToString()); } catch (Exception ex) { ZCRMLogger.LogError(ex); throw new ZohoOAuthException("Exception while fetching User email from access token, Make sure AAAserver.profile.Read scope is included while generating the Grant token."); } }