// Public Application Authenication - a46c26f6-7874-4bf4-b5b0-d221eb2c54f9

        protected XeroCoreApi XeroAuthenticate(Page inpage, bool authpagereturnedauthentication, string incode)
        {
            // This procedure will return w working XeroCoreApi if successful and nothing otherwise
            // Set client secrets for general use and then load any override ones from the web.config file
            Consumer myxeroconsumer = new Consumer("EQG3PH0JMUA2OYTGWXDN67BJDCVNFF", "YWTHX3SAJUUV2FV96IMRW1OJ2E06HH");
            dynamic  myxerouser     = new ApiUser {
                Name = "*****@*****.**"
            };

            // If user defined ID and Secrets exist then use those instead

            if ((System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerKey") != null))
            {
                if ((System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerSecret") != null))
                {
                    if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerKey").ToString()))
                    {
                        myxeroconsumer = new Consumer(System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerKey").ToString(), System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerSecret").ToString());
                    }
                }
            }
            // Define Page Call Information
            dynamic myxerocallbackurl       = "http://peoplehr.virtualdcs.co.uk/ExpenseTransfer.aspx";
            dynamic myxeromemorystore       = new MemoryAccessTokenStore();
            dynamic myxerorequestTokenStore = new MemoryRequestTokenStore();
            dynamic myxerobaseapiurl        = "https://api.xero.com";

            // Authenticate with Xero
            PublicMvcAuthenticator myxeroauthenticator = new PublicMvcAuthenticator(myxerobaseapiurl, myxerobaseapiurl, myxerocallbackurl, myxeromemorystore, myxeroconsumer, myxerorequestTokenStore);

            if (authpagereturnedauthentication == false)
            {
                // Redirect to the authentication page
                string requri = myxeroauthenticator.GetRequestTokenAuthorizeUrl(myxerouser.Name);
                if (!string.IsNullOrEmpty(requri))
                {
                    Response.Redirect(requri, true);
                }
                return(null);
            }
            else
            {
                // Validate token using querystrings that have been returned from the authentication process
                IToken myxerotoken = myxeroauthenticator.RetrieveAndStoreAccessToken(myxerouser.Name, Request.QueryString["oauth_token"].ToString(), Request.QueryString["oauth_verifier"].ToString(), Request.QueryString["org"].ToString());
                if ((myxerotoken != null))
                {
                    XeroCoreApi myxeroapi = new XeroCoreApi("https://api.xero.com", myxeroauthenticator, myxeroconsumer, myxerouser);
                    return(myxeroapi);
                }
                else
                {
                    return(null);
                }
            }
        }
        static XeroApiHelper()
        {
            // Refer to README.md for details
            ////var callbackUrl = "http://mywebsite.url/Home/Authorize";

            var callbackUrl = "http://*****:*****@"C:\Dev\your_public_privatekey.pfx";
            ////var signingCertificatePassword = "******";

            // Public Application Settings
            var publicConsumer = new Consumer(consumerKey, consumerSecret);

            var publicAuthenticator = new PublicMvcAuthenticator(baseApiUrl, baseApiUrl, callbackUrl, memoryStore,
                                                                 publicConsumer, requestTokenStore);

            var publicApplicationSettings = new ApplicationSettings
            {
                BaseApiUrl    = baseApiUrl,
                Consumer      = publicConsumer,
                Authenticator = publicAuthenticator
            };

            // Partner Application Settings
            ////var partnerConsumer = new Consumer(consumerKey, consumerSecret);

            ////var partnerAuthenticator = new PartnerMvcAuthenticator(baseApiUrl, baseApiUrl, callbackUrl,
            ////        memoryStore, signingCertificatePath,
            ////        partnerConsumer, requestTokenStore, signingCertificatePassword);

            ////var partnerApplicationSettings = new ApplicationSettings
            ////{
            ////    BaseApiUrl = baseApiUrl,
            ////    Consumer = partnerConsumer,
            ////    Authenticator = partnerAuthenticator
            ////};

            // Pick one
            // Choose what sort of application is appropriate. Comment out the above code (Partner Application Settings/Public Application Settings) that are not used.

            _applicationSettings = publicApplicationSettings;
            ////_applicationSettings = partnerApplicationSettings;
        }
Example #3
0
        static XeroApiHelper()
        {
            // Refer to README.md for details
            var callbackUrl       = "http://mywebsite.url/Home/Authorize";
            var memoryStore       = new MemoryAccessTokenStore();
            var requestTokenStore = new MemoryRequestTokenStore();
            var baseApiUrl        = "https://api.xero.com";
            var basePartnerApiUrl = "https://api-partner.network.xero.com";

            var signingCertificatePath     = @"C:\Dev\your_public_privatekey.pfx";
            var signingCertificatePassword = "******";
            var clientCertificatePath      = @"C:\Dev\your_entrust_cert.p12";
            var clientCertificatePassword  = "******";

            var publicAppConsumerKey    = "your-public-app-consumer-key";
            var publicAppConsumerSecret = "your-public-app-consumer-secret";
            var partnerConsumerKey      = "your-partner-app-consumer-key";
            var partnerConsumerSecret   = "your-partner-app-consumer-secret";

            // Public Application Settings
            var publicConsumer = new Consumer(publicAppConsumerKey, publicAppConsumerSecret);

            var publicAuthenticator = new PublicMvcAuthenticator(baseApiUrl, baseApiUrl, callbackUrl, memoryStore,
                                                                 publicConsumer, requestTokenStore);

            var publicApplicationSettings = new ApplicationSettings
            {
                BaseApiUrl    = baseApiUrl,
                Consumer      = publicConsumer,
                Authenticator = publicAuthenticator
            };

            // Partner Application Settings
            var partnerConsumer = new Consumer(partnerConsumerKey, partnerConsumerSecret);

            var partnerAuthenticator = new PartnerMvcAuthenticator(basePartnerApiUrl, baseApiUrl, callbackUrl,
                                                                   memoryStore, signingCertificatePath, clientCertificatePath, clientCertificatePassword,
                                                                   partnerConsumer, requestTokenStore, signingCertificatePassword);

            var partnerApplicationSettings = new ApplicationSettings
            {
                BaseApiUrl    = basePartnerApiUrl,
                Consumer      = partnerConsumer,
                Authenticator = partnerAuthenticator
            };

            // Pick one
            // Choose what sort of application is appropriate. Comment out the above code (Partner Application Settings/Public Application Settings) that are not used.

            //_applicationSettings = publicApplicationSettings;
            _applicationSettings = partnerApplicationSettings;
        }
    protected XeroCoreApi XeroAuthenticate(Page inpage, bool authpagereturnedauthentication, string incode)
    {
        Consumer myxeroconsumer = new Consumer("TTLGJ2OSYVNHKFCS2VHBUMAJYOYOJJ", "IXUX1RCEYMEMI4QXLELG0G779EWCTJ");
        dynamic  myxerouser     = new ApiUser {
            Name = "Barry Jone"
        };



        if ((System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerKey") != null))
        {
            if ((System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerSecret") != null))
            {
                if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerKey").ToString()))
                {
                    myxeroconsumer = new Consumer(System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerKey").ToString(), System.Configuration.ConfigurationManager.AppSettings.Get("XeroApiConsumerSecret").ToString());
                }
            }
        }


        dynamic myxerocallbackurl       = "http://medialeven.com/System/StripeToXero.aspx";
        dynamic myxeromemorystore       = new MemoryAccessTokenStore();
        dynamic myxerorequestTokenStore = new MemoryRequestTokenStore();
        dynamic myxerobaseapiurl        = "https://api.xero.com";


        PublicMvcAuthenticator myxeroauthenticator = new PublicMvcAuthenticator(myxerobaseapiurl, myxerobaseapiurl, myxerocallbackurl, myxeromemorystore, myxeroconsumer, myxerorequestTokenStore);

        if (authpagereturnedauthentication == false)
        {
            string requri = myxeroauthenticator.GetRequestTokenAuthorizeUrl(myxerouser.Name);
            if (!string.IsNullOrEmpty(requri))
            {
                Response.Redirect(requri, true);
            }
            return(null);
        }
        else
        {
            IToken myxerotoken = myxeroauthenticator.RetrieveAndStoreAccessToken(myxerouser.Name, Request.QueryString["oauth_token"].ToString(), Request.QueryString["oauth_verifier"].ToString(), Request.QueryString["org"].ToString());
            if ((myxerotoken != null))
            {
                XeroCoreApi myxeroapi = new XeroCoreApi("https://api.xero.com", myxeroauthenticator, myxeroconsumer, myxerouser);
                return(myxeroapi);
            }
            else
            {
                return(null);
            }
        }
    }
Example #5
0
        static XeroApiHelper()
        {
            var memoryStore       = new MemoryAccessTokenStore();
            var requestTokenStore = new MemoryRequestTokenStore();

            // These values will be read from Web.config first, then the defined value here
            var callbackUrl = ConfigurationManager.AppSettings["XeroApiCallBackUrl"] ?? "https://*****:*****@"C:\Dev\your_public_privatekey.pfx";
            //var signingCertificatePassword = "******";

            // Public Application Settings
            var publicConsumer = new Consumer(consumerKey, consumerSecret);

            var publicAuthenticator = new PublicMvcAuthenticator(baseApiUrl, tokenUrl, callbackUrl, memoryStore, publicConsumer, requestTokenStore);

            var publicApplicationSettings = new XeroApiSetting
            {
                BaseApiUrl    = baseApiUrl,
                Consumer      = publicConsumer,
                Authenticator = publicAuthenticator
            };

            // Partner Application Settings
            //var partnerConsumer = new Consumer(consumerKey, consumerSecret);

            //var partnerAuthenticator = new PartnerMvcAuthenticator(baseApiUrl, baseApiUrl, callbackUrl,
            //        memoryStore, signingCertificatePath,
            //        partnerConsumer, requestTokenStore, signingCertificatePassword);

            //var partnerApplicationSettings = new ApplicationSettings
            //{
            //    BaseApiUrl = baseApiUrl,
            //    Consumer = partnerConsumer,
            //    Authenticator = partnerAuthenticator
            //};

            // Pick one
            // Choose what sort of application is appropriate. Comment out the above code (Partner Application Settings/Public Application Settings) that are not used.

            _setting = publicApplicationSettings;
            //_applicationSettings = partnerApplicationSettings;
        }
Example #6
0
        static XeroFunctions()
        {
            var memoryStore       = new MemoryAccessTokenStore();
            var requestTokenStore = new MemoryRequestTokenStore();

            var publicConsumer = new Consumer(Constants.Key, Constants.Secret);

            var publicAuthenticator = new PublicMvcAuthenticator(Constants.BaseUri, Constants.BaseUri, Constants.CallBackUri, memoryStore,
                                                                 publicConsumer, requestTokenStore);

            var publicApplicationSettings = new ApplicationSettings
            {
                BaseApiUrl    = Constants.BaseUri,
                Consumer      = publicConsumer,
                Authenticator = publicAuthenticator
            };

            _applicationSettings = publicApplicationSettings;
        }
Example #7
0
        static XeroApiHelper()
        {
            var callbackUrl = "http://localhost:61795/Home/Authorize";
            //var callbackUrl = "https://xeroaccounts.co.uk/Home/Authorize";
            var memoryStore       = new MemoryAccessTokenStore();
            var requestTokenStore = new MemoryRequestTokenStore();
            var baseApiUrl        = "https://api.xero.com";
            // Consumer details for Application
            var consumerKey               = ConfigurationManager.AppSettings["ConsumerKey"];
            var consumerSecret            = ConfigurationManager.AppSettings["ConsumerSecret"];
            var publicConsumer            = new Consumer(consumerKey, consumerSecret);
            var publicAuthenticator       = new PublicMvcAuthenticator(baseApiUrl, baseApiUrl, callbackUrl, memoryStore, publicConsumer, requestTokenStore);
            var publicApplicationSettings = new ApplicationSettings
            {
                BaseApiUrl    = baseApiUrl,
                Consumer      = publicConsumer,
                Authenticator = publicAuthenticator
            };

            _applicationSettings = publicApplicationSettings;
        }