/// <summary> /// Creates the OAuth session. /// </summary> /// <returns></returns> private static IOAuthSession CreateOAuthSession() { const string userAgent = "Xero.API.ScreenCastWeb v2.0"; if (ConfigurationManager.AppSettings["XeroApiSignatureMethod"] == "HMAC-SHA1") { // Public App return(new XeroApiPublicSession( userAgent, ConfigurationManager.AppSettings["XeroApiConsumerKey"], // Consumer Key ConfigurationManager.AppSettings["XeroApiConsumerSecret"], // Consumer Secret CurrentTokenRepository)); // Token Repository } if (ConfigurationManager.AppSettings["XeroApiSignatureMethod"] == "RSA-SHA1") { if (ConfigurationManager.AppSettings["XeroApiBaseUrl"].ToLower().IndexOf("partner") > 0) { // Partner App return(new XeroApiPartnerSession( userAgent, ConfigurationManager.AppSettings["XeroApiConsumerKey"], // Consumer Key CertificateRepository.GetOAuthSigningCertificate(), // OAuth Signing Certificate CertificateRepository.GetClientSslCertificate(), // Client SSL Certificate CurrentTokenRepository)); // Token Repository } else { // Private App return(new XeroApiPrivateSession( userAgent, ConfigurationManager.AppSettings["XeroApiConsumerKey"], // Consumer Key CertificateRepository.GetOAuthSigningCertificate())); // OAuth Signing Certificate } } throw new ConfigurationErrorsException("The configuration for a Public/Private/Partner app cannot be determined."); }
public IOAuthSession GetOAuthSession() { OAuthConsumerContext consumerContext = new OAuthConsumerContext() { ConsumerKey = ConfigurationManager.AppSettings["XeroApiConsumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["XeroApiConsumerSecret"], SignatureMethod = ConfigurationManager.AppSettings["XeroApiSignatureMethod"], UseHeaderForOAuthParameters = true, UserAgent = string.Format("Xero.API.ScreenCastWeb v1.0"), Key = CertificateRepository.GetOAuthSigningCertificatePrivateKey() }; OAuthSession oAuthSession = new OAuthSession( consumerContext, ConfigurationManager.AppSettings["XeroApiRequestTokenEndpoint"], ConfigurationManager.AppSettings["XeroApiAuthorisationEndpoint"], ConfigurationManager.AppSettings["XeroApiAccessTokenEndpoint"], ConfigurationManager.AppSettings["XeroApiCallbackUrl"]); // Replace the default ConsumerRequestFactory with one that can construct a ConsumerRequest with Client SSL certificates. oAuthSession.ConsumerRequestFactory = new DefaultConsumerRequestFactory(CertificateRepository.GetClientSslCertificateFactory()); return(oAuthSession); }