Example #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);
     }
 }
Example #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);
        }
Example #3
0
        //TODO: the method throws three exceptions and check for null exception on access_token.
        public string GetUserMailId(string accessToken)
        {
            try
            {
                ZohoHTTPConnector conn = new ZohoHTTPConnector()
                {
                    Url = ZohoOAuth.GetUserInfoURL()
                };
                //conn.AddHeader("Authorization", ZohoOAuthConstants.AuthHeaderPrefix + accessToken);
                conn.AddHeader("Authorization", ZohoOAuthConstants.Bearer + accessToken);
                string  response     = conn.Get();
                JObject responseJSON = JObject.Parse(response);

                if (response == null)
                {
                    return(null);
                }
                else
                {
                    return(responseJSON["Email"].ToString());
                }
            }
            catch (WebException) { throw; }
        }