示例#1
0
        public static List <Employee> getEmployeeList(IppRealmOAuthProfile profile)
        {
            ServiceContext          serviceContext       = getServiceContext(profile);
            QueryService <Employee> employeeQueryService = new QueryService <Employee>(serviceContext);

            return(employeeQueryService.Select(c => c).ToList());
        }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            try
            {

                if (accessToken.Text.Length == 0) { throw new Exception("Invalid Access Token"); }
                if (accessSecret.Text.Length == 0) { throw new Exception("Invalid Access Secret"); }
                if (realmId.Text.Length == 0) { throw new Exception("Invalid Realm ID"); }

                IppRealmOAuthProfile ippRealmOAuthProfile = new IppRealmOAuthProfile();
                ippRealmOAuthProfile.realmId = realmId.Text;
                switch (dataSource.SelectedValue.ToLower())
                {
                    case "qbo": ippRealmOAuthProfile.dataSource = (int)IntuitServicesType.QBO; break;
                    case "qbd": ippRealmOAuthProfile.dataSource = (int)IntuitServicesType.QBD; break;
                }
                ippRealmOAuthProfile.accessToken = accessToken.Text;
                ippRealmOAuthProfile.accessSecret = accessSecret.Text;
                ippRealmOAuthProfile.expirationDateTime = DateTime.Now;

                RestHelper.getEmployeeList(ippRealmOAuthProfile);

                ippRealmOAuthProfile.Save();
            }
            catch
            {
                errorMessage.Visible = true;
            }
        }
 public static void clearProfile(IppRealmOAuthProfile profile)
 {
     profile.accessToken = "";
     profile.accessSecret = "";
     profile.realmId = "";
     profile.dataSource = -1;
     profile.Save();
 }
示例#4
0
        private static ServiceContext getServiceContext(IppRealmOAuthProfile profile)
        {
            var consumerKey    = ConfigurationManager.AppSettings["consumerKey"].ToString();
            var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
            OAuthRequestValidator oauthValidator = new OAuthRequestValidator(profile.accessToken, profile.accessSecret, consumerKey, consumerSecret);

            return(new ServiceContext(profile.realmId, (IntuitServicesType)profile.dataSource, oauthValidator));
        }
示例#5
0
 public static void clearProfile(IppRealmOAuthProfile profile)
 {
     profile.accessToken  = "";
     profile.accessSecret = "";
     profile.realmId      = "";
     profile.dataSource   = -1;
     profile.Save();
 }
示例#6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //This creates an administrator for the sample app if it does not exist
     if (Membership.FindUsersByName("admin").Count == 0)
     {
         MembershipUser newUser = Membership.CreateUser("admin", "intuit");
     }
     try { IppRealmOAuthProfile ippRealmOAuthProfile = IppRealmOAuthProfile.Read(); }
     catch { }
 }
 protected void disconnect_Click(object sender, EventArgs e)
 {
     try
     {
         RestHelper.disconnectRealm(IppRealmOAuthProfile.Read());
     }
     catch
     {
     }
     finally { loadVisibleSections(); }
 }
示例#8
0
 public void ToggleBlueDotMenuVisibility()
 {
     if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated && System.Web.HttpContext.Current.User.Identity.Name == "admin" && RestHelper.appTokensSet() && !Request.FilePath.Contains("OAuth"))
     {
         IppRealmOAuthProfile profile = IppRealmOAuthProfile.Read();
         blueDotMenu.Visible = profile.accessToken.Length > 0;
     }
     else
     {
         blueDotMenu.Visible = false;
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated || !RestHelper.appTokensSet() || IppRealmOAuthProfile.Read().accessToken.Length == 0)
         {
             Response.Redirect("~/Default.aspx");
         }
         employeesView.DataSource = RestHelper.getEmployeeList(IppRealmOAuthProfile.Read());
         employeesView.DataBind();
     }
     catch
     {
     }
 }
        private static IppRealmOAuthProfile callReconnect(IppRealmOAuthProfile ippRealmOAuthProfile)
        {
            string      xmlResponse       = RestHelper.callPlatform(ippRealmOAuthProfile, "https://appcenter.intuit.com/api/v1/Connection/Reconnect");
            XmlDocument reconnectResponse = new XmlDocument();

            reconnectResponse.LoadXml(xmlResponse);
            foreach (XmlNode childNode in reconnectResponse.DocumentElement)
            {
                switch (childNode.Name)
                {
                case "OAuthToken": ippRealmOAuthProfile.accessToken = childNode.InnerText; break;

                case "OAuthTokenSecret": ippRealmOAuthProfile.accessSecret = childNode.InnerText; break;

                default: break;
                }
            }
            ippRealmOAuthProfile.expirationDateTime = DateTime.Now.AddMonths(6);
            return(ippRealmOAuthProfile);
        }
 private void loadVisibleSections()
 {
     notLoggedIn.Visible       = false;
     notConnected.Visible      = false;
     connected.Visible         = false;
     appTokensNotFound.Visible = false;
     if (!RestHelper.appTokensSet())
     {
         appTokensNotFound.Visible = true;
     }
     else if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
     {
         notLoggedIn.Visible = true;
     }
     else
     {
         notConnected.Visible = IppRealmOAuthProfile.Read().accessToken == "";
         connected.Visible    = IppRealmOAuthProfile.Read().accessToken != "";
     }
     (this.Master as SiteMaster).ToggleBlueDotMenuVisibility();
 }
示例#12
0
        public static string callPlatform(IppRealmOAuthProfile profile, string url)
        {
            OAuthConsumerContext consumerContext = new OAuthConsumerContext
            {
                ConsumerKey     = ConfigurationManager.AppSettings["consumerKey"].ToString(),
                SignatureMethod = SignatureMethod.HmacSha1,
                ConsumerSecret  = ConfigurationManager.AppSettings["consumerSecret"].ToString()
            };

            OAuthSession oSession = new OAuthSession(consumerContext, Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlRequestToken,
                                                     Constants.OauthEndPoints.AuthorizeUrl,
                                                     Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlAccessToken);

            oSession.ConsumerContext.UseHeaderForOAuthParameters = true;
            if (profile.accessToken.Length > 0)
            {
                oSession.AccessToken = new TokenBase
                {
                    Token       = profile.accessToken,
                    ConsumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(),
                    TokenSecret = profile.accessSecret
                };

                IConsumerRequest conReq = oSession.Request();
                conReq = conReq.Get();
                conReq = conReq.ForUrl(url);
                try
                {
                    conReq = conReq.SignWithToken();
                    return(conReq.ReadBody());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return("");
        }
示例#13
0
        protected void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (accessToken.Text.Length == 0)
                {
                    throw new Exception("Invalid Access Token");
                }
                if (accessSecret.Text.Length == 0)
                {
                    throw new Exception("Invalid Access Secret");
                }
                if (realmId.Text.Length == 0)
                {
                    throw new Exception("Invalid Realm ID");
                }

                IppRealmOAuthProfile ippRealmOAuthProfile = new IppRealmOAuthProfile();
                ippRealmOAuthProfile.realmId = realmId.Text;
                switch (dataSource.SelectedValue.ToLower())
                {
                case "qbo": ippRealmOAuthProfile.dataSource = (int)IntuitServicesType.QBO; break;

                case "qbd": ippRealmOAuthProfile.dataSource = (int)IntuitServicesType.QBD; break;
                }
                ippRealmOAuthProfile.accessToken        = accessToken.Text;
                ippRealmOAuthProfile.accessSecret       = accessSecret.Text;
                ippRealmOAuthProfile.expirationDateTime = DateTime.Now;

                RestHelper.getEmployeeList(ippRealmOAuthProfile);

                ippRealmOAuthProfile.Save();
            }
            catch
            {
                errorMessage.Visible = true;
            }
        }
        public static string callPlatform(IppRealmOAuthProfile profile, string url)
        {
            OAuthConsumerContext consumerContext = new OAuthConsumerContext
            {
                ConsumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(),
                SignatureMethod = SignatureMethod.HmacSha1,
                ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString()
            };

            OAuthSession oSession = new OAuthSession(consumerContext, Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlRequestToken,
                                  Constants.OauthEndPoints.AuthorizeUrl,
                                  Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlAccessToken);

            oSession.ConsumerContext.UseHeaderForOAuthParameters = true;
            if (profile.accessToken.Length > 0)
            {
                oSession.AccessToken = new TokenBase
                {
                    Token = profile.accessToken,
                    ConsumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(),
                    TokenSecret = profile.accessSecret
                };

                IConsumerRequest conReq = oSession.Request();
                conReq = conReq.Get();
                conReq = conReq.ForUrl(url);
                try
                {
                    conReq = conReq.SignWithToken();
                    return conReq.ReadBody();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return "";
        }
        public static IppRealmOAuthProfile Read()
        {
            if (!File.Exists("ipp.xml"))
            {
                return(new IppRealmOAuthProfile());
            }
            string encryptedRealmProfile = File.ReadAllText("ipp.xml", Encoding.Unicode);

            if (encryptedRealmProfile.Length == 0)
            {
                return(new IppRealmOAuthProfile());
            }
            string               decryptedRealmProfile = StringCipher.Decrypt(encryptedRealmProfile, "<FILL_IN_PASSWORD_OR_OTHER_UNIQUE_APPLICATION_VALUE>");
            TextReader           textReader            = new StringReader(decryptedRealmProfile);
            XmlSerializer        xmlSerializer         = new XmlSerializer((new IppRealmOAuthProfile()).GetType());
            IppRealmOAuthProfile ippRealmOAuthProfile  = (IppRealmOAuthProfile)xmlSerializer.Deserialize(textReader);

            if (ippRealmOAuthProfile.expirationDateTime.Subtract(DateTime.Now).TotalDays < 30)
            {
                ippRealmOAuthProfile = callReconnect(ippRealmOAuthProfile);
                ippRealmOAuthProfile.Save();
            }
            return(ippRealmOAuthProfile);
        }
 private static IppRealmOAuthProfile callReconnect(IppRealmOAuthProfile ippRealmOAuthProfile)
 {
     string xmlResponse = RestHelper.callPlatform(ippRealmOAuthProfile, "https://appcenter.intuit.com/api/v1/Connection/Reconnect");
     XmlDocument reconnectResponse = new XmlDocument();
     reconnectResponse.LoadXml(xmlResponse);
     foreach (XmlNode childNode in reconnectResponse.DocumentElement)
     {
         switch (childNode.Name)
         {
             case "OAuthToken": ippRealmOAuthProfile.accessToken = childNode.InnerText; break;
             case "OAuthTokenSecret": ippRealmOAuthProfile.accessSecret = childNode.InnerText; break;
             default: break;
         }
     }
     ippRealmOAuthProfile.expirationDateTime = DateTime.Now.AddMonths(6);
     return ippRealmOAuthProfile;
 }
示例#17
0
        private static DataService getDataService(IppRealmOAuthProfile profile)
        {
            ServiceContext serviceContext = getServiceContext(profile);

            return(new DataService(serviceContext));
        }
 private static DataService getDataService(IppRealmOAuthProfile profile)
 {
     ServiceContext serviceContext = getServiceContext(profile);
     return new DataService(serviceContext);
 }
 public static List<Employee> getEmployeeList(IppRealmOAuthProfile profile)
 {
     ServiceContext serviceContext = getServiceContext(profile);
     QueryService<Employee> employeeQueryService = new QueryService<Employee>(serviceContext);
     return employeeQueryService.Select(c => c).ToList();
 }
 public static void disconnectRealm(IppRealmOAuthProfile profile)
 {
     RestHelper.callPlatform(profile, Constants.IppEndPoints.DisconnectUrl);
     clearProfile(profile);
 }
示例#21
0
 public static void disconnectRealm(IppRealmOAuthProfile profile)
 {
     RestHelper.callPlatform(profile, Constants.IppEndPoints.DisconnectUrl);
     clearProfile(profile);
 }
 private static ServiceContext getServiceContext(IppRealmOAuthProfile profile)
 {
     var consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString();
     var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"].ToString();
     OAuthRequestValidator oauthValidator = new OAuthRequestValidator(profile.accessToken, profile.accessSecret, consumerKey, consumerSecret);
     return new ServiceContext(profile.realmId, (IntuitServicesType)profile.dataSource, oauthValidator);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            IppRealmOAuthProfile profile = IppRealmOAuthProfile.Read();

            Response.Write(RestHelper.callPlatform(profile, Constants.IppEndPoints.BlueDotAppMenuUrl));
        }