public void ThirdPartyAuthorizationForToken()
 {
     IThirdPartyAuthorization thirdPartyAuthorization = new TokenAuthorization(Constants.AccessToken, Constants.TokenSecret);
     signCredential.ThirdPartyAuthorization = thirdPartyAuthorization;
     Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).AccessToken, Constants.AccessToken);
     Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).AccessTokenSecret, Constants.TokenSecret);
 }
        /// <summary>
        /// Processing for TokenAuthorization} using SignatureCredential
        /// </summary>
        /// <param name="certCredential"></param>
        /// <param name="toknAuthorization"></param>
        /// <returns></returns>
        protected override Dictionary<string, string> ProcessTokenAuthorization(
                CertificateCredential certCredential, TokenAuthorization toknAuthorization)
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            try
            {
                OAuthGenerator signGenerator = new OAuthGenerator(certCredential.UserName, certCredential.Password);
                signGenerator.setHTTPMethod(OAuthGenerator.HTTPMethod.POST);
                signGenerator.setToken(toknAuthorization.AccessToken);
                signGenerator.setTokenSecret(toknAuthorization.TokenSecret);
                string tokenTimeStamp = Timestamp;
                signGenerator.setTokenTimestamp(tokenTimeStamp);
                log.Debug("token = " + toknAuthorization.AccessToken + " tokenSecret=" + toknAuthorization.TokenSecret + " uri=" + endpointURL);
                signGenerator.setRequestURI(endpointURL);

                //Compute Signature
                string sign = signGenerator.ComputeSignature();
                log.Debug("Permissions signature: " + sign);
                string authorization = "token=" + toknAuthorization.AccessToken + ",signature=" + sign + ",timestamp=" + tokenTimeStamp;
                log.Debug("Authorization string: " + authorization);
                headers.Add(BaseConstants.PAYPAL_AUTHORIZATION_MERCHANT, authorization);
            }
            catch (OAuthException ae)
            {
                throw ae;
            }
            return headers;
        }
        /// <summary>
        /// Processing TokenAuthorization} using SignatureCredential
        /// </summary>
        /// <param name="signCredential"></param>
        /// <param name="tokenAuthorize"></param>
        /// <returns></returns>
        protected internal override Dictionary<string, string> ProcessTokenAuthorization(
                SignatureCredential signCredential, TokenAuthorization tokenAuthorize)
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            try
            {
                OAuthGenerator generatorOAuth = new OAuthGenerator(signCredential.UserName, signCredential.Password);
                //generatorOAuth.SetHttpPMethod(HttpMethod.POST);
                generatorOAuth.SetToken(tokenAuthorize.AccessToken);
                generatorOAuth.SetTokenSecret(tokenAuthorize.AccessTokenSecret);
                string tokenTimeStamp = Timestamp;
                generatorOAuth.SetTokenTimestamp(tokenTimeStamp);
                logger.DebugFormat("token = " + tokenAuthorize.AccessToken + " tokenSecret=" + tokenAuthorize.AccessTokenSecret + " uri=" + endpointUrl);
                generatorOAuth.SetRequestUri(endpointUrl);

                //Compute Signature
                string sign = generatorOAuth.ComputeSignature();
                logger.DebugFormat("Permissions signature: " + sign);
                string authorization = "token=" + tokenAuthorize.AccessToken + ",signature=" + sign + ",timestamp=" + tokenTimeStamp;
                logger.DebugFormat("Authorization string: " + authorization);
                headers.Add(BaseConstants.PayPalAuthorizationPlatformHeader, authorization);
            }
            catch (OAuthException oex)
            {
                throw oex;
            }
            return headers;
        }
        /// <summary>
        /// Processing for TokenAuthorization} using SignatureCredential
        /// </summary>
        /// <param name="certCredential"></param>
        /// <param name="tokenAuthorize"></param>
        /// <returns></returns>
        protected override Dictionary<string, string> ProcessTokenAuthorization(CertificateCredential certCredential, TokenAuthorization tokenAuthorize)
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            try
            {
                OAuthGenerator signGenerator = new OAuthGenerator(certCredential.UserName, certCredential.Password);
                signGenerator.SetToken(tokenAuthorize.AccessToken);
                signGenerator.SetTokenSecret(tokenAuthorize.AccessTokenSecret);
                string tokenTimeStamp = Timestamp;
                signGenerator.SetTokenTimestamp(tokenTimeStamp);
                logger.DebugFormat("token = " + tokenAuthorize.AccessToken + " tokenSecret=" + tokenAuthorize.AccessTokenSecret + " uri=" + endpointUrl);
                signGenerator.SetRequestUri(endpointUrl);

                //Compute Signature
                string sign = signGenerator.ComputeSignature();
                logger.DebugFormat("Permissions signature: " + sign);
                string authorization = "token=" + tokenAuthorize.AccessToken + ",signature=" + sign + ",timestamp=" + tokenTimeStamp;
                logger.DebugFormat("Authorization string: " + authorization);
                headers.Add(BaseConstants.PayPalAuthorizationMerchantHeader, authorization);
            }
            catch (OAuthException oex)
            {
                throw oex;
            }
            return headers;
        }
 public void ThirdPartyAuthorizationTestForToken()
 {
     IThirdPartyAuthorization thirdPartyAuthorization = new TokenAuthorization(UnitTestConstants.AccessToken, UnitTestConstants.TokenSecret);
     certCredential.ThirdPartyAuthorization = thirdPartyAuthorization;
     Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).AccessToken, UnitTestConstants.AccessToken);
     Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).TokenSecret, UnitTestConstants.TokenSecret);
 }
 public void GenerateHeaderStrategyToken()
 {
     certCredential = new CertificateCredential("testusername", "testpassword", "sdk-cert.p12", "KJAERUGBLVF6Y");
     certSOAPHeaderAuthStrategy = new CertificateSOAPHeaderAuthStrategy();
     TokenAuthorization toknAuthorization = new TokenAuthorization("accessToken", "tokenSecret");
     certSOAPHeaderAuthStrategy.ThirdPartyAuthorization = toknAuthorization;
     string payload = certSOAPHeaderAuthStrategy.GenerateHeaderStrategy(certCredential);
     Assert.AreEqual("<ns:RequesterCredentials/>", payload);
 }
 public void GenerateHeaderStrategyWithToken()
 {
     certHttpHeaderAuthStrategy = new CertificateHttpHeaderAuthStrategy(Constants.APIEndpointSOAP);
     TokenAuthorization toknAuthorization = new TokenAuthorization(Constants.AccessToken, Constants.TokenSecret);
     CertificateCredential certCredential = new CertificateCredential("testusername", "testpassword", "sdk-cert.p12", "KJAERUGBLVF6Y", toknAuthorization);
     Dictionary<string, string> header = certHttpHeaderAuthStrategy.GenerateHeaderStrategy(certCredential);
     string authHeader = header[BaseConstants.PayPalAuthorizationMerchantHeader];
     string[] headers = authHeader.Split(',');
     Assert.AreEqual("token=" + Constants.AccessToken, headers[0]);
 }
 public void GenerateHeaderStrategyWithTokenTest()
 {
     certHttpHeaderAuthStrategy = new CertificateHttpHeaderAuthStrategy(UnitTestConstants.APIEndpointSOAP);
     TokenAuthorization toknAuthorization = new TokenAuthorization(UnitTestConstants.AccessToken, UnitTestConstants.TokenSecret);
     certCredential = new CertificateCredential("testusername", "testpassword", "sdk-cert.p12", "KJAERUGBLVF6Y", toknAuthorization);
     Dictionary<string, string> header = certHttpHeaderAuthStrategy.GenerateHeaderStrategy(certCredential);
     string authHeader = header[BaseConstants.PAYPAL_AUTHORIZATION_PLATFORM_HEADER];
     string[] headers = authHeader.Split(',');
     Assert.AreEqual("token=" + UnitTestConstants.AccessToken, headers[0]);
 }
 public void GenerateHeaderStrategyToken()
 {
     signCredential = new SignatureCredential("testusername", "testpassword", "testsignature");
     signSOAPHeaderAuthStrategy = new SignatureSOAPHeaderAuthStrategy();
     TokenAuthorization toknAuthorization = new TokenAuthorization("accessToken", "tokenSecret");
     signSOAPHeaderAuthStrategy.ThirdPartyAuthorization = toknAuthorization;
     signCredential.ThirdPartyAuthorization = toknAuthorization;
     string payload = signSOAPHeaderAuthStrategy.GenerateHeaderStrategy(signCredential);
     Assert.AreEqual("<ns:RequesterCredentials/>", payload);
 }
 public void GenerateHeaderStrategyWithToken()
 {
     signHttpHeaderAuthStrategy = new SignatureHttpHeaderAuthStrategy(Constants.APIEndpointNVP);
     TokenAuthorization toknAuthorization = new TokenAuthorization(Constants.AccessToken, Constants.TokenSecret);
     signCredential = new SignatureCredential("testusername", "testpassword", "testsignature", toknAuthorization);
     Dictionary<string, string> header = signHttpHeaderAuthStrategy.GenerateHeaderStrategy(signCredential);
     string authHeader = header[BaseConstants.PayPalAuthorizationPlatformHeader];
     string[] headers = authHeader.Split(',');
     Assert.AreEqual("token=" + Constants.AccessToken, headers[0]);
 }
 public void GenerateHeaderStrategyWithToken()
 {
     signHttpHeaderAuthStrategy = new SignatureHttpHeaderAuthStrategy(UnitTestConstants.APIEndpointSOAP);
     TokenAuthorization toknAuthorization = new TokenAuthorization(UnitTestConstants.AccessToken, UnitTestConstants.TokenSecret);
     signCredential = new SignatureCredential("testusername", "testpassword", "testsignature", toknAuthorization);
     Dictionary<string, string> header = signHttpHeaderAuthStrategy.GenerateHeaderStrategy(signCredential);
     string authHeader = header[BaseConstants.PAYPAL_AUTHORIZATION_MERCHANT];
     string[] headers = authHeader.Split(',');
     Assert.AreEqual("token=" + UnitTestConstants.AccessToken, headers[0]);
 }
        /// <summary>
        ///  Returns the credentials as configured in the application configuration
        /// </summary>
        /// <returns></returns>
        private ICredential GetCredentials()
        {
            ICredential returnCredential = null;
            try
            {
                CredentialManager credentialMngr = CredentialManager.Instance;
                returnCredential = credentialMngr.GetCredentials(this.config, apiUserName);

                if (!string.IsNullOrEmpty(accessToken))
                {

                    // Set third party authorization to token
                    // if token is sent as part of request call
                    IThirdPartyAuthorization thirdPartyAuthorization = new TokenAuthorization(accessToken, tokenSecret);
                    if (returnCredential is SignatureCredential)
                    {
                        SignatureCredential signCredential = (SignatureCredential)returnCredential;
                        signCredential.ThirdPartyAuthorization = thirdPartyAuthorization;
                    }
                    else if (returnCredential is CertificateCredential)
                    {
                        CertificateCredential certCredential = (CertificateCredential)returnCredential;
                        certCredential.ThirdPartyAuthorization = thirdPartyAuthorization;
                    }
                }
            }
            catch(System.Exception ex)
            {
                throw ex;
            }
            return returnCredential;
        }
 public void ArgumentExceptionTest()
 {
     TokenAuthorization toknAuthorization = new TokenAuthorization(null, null);
 }
        private SignatureCredential SetThirdPartyAuthorization(HttpContext context)
        {
            SignatureCredential cred = null;
            if (context.Request.Params["authentication"] != null)
            {
                IThirdPartyAuthorization thirdPartyAuth = new TokenAuthorization(
            context.Request.Params["accessToken"],
            context.Request.Params["tokenSecret"]);

                cred = new SignatureCredential("jb-us-seller_api1.paypal.com",
                        "WX4WTU3S8MY44S7F",
                        "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy");

                cred.ApplicationId = "APP-80W284485P519543T";
                cred.ThirdPartyAuthorization = thirdPartyAuth;

            }
            if (context.Request.Params["permission$authentication"] != null)
            {
                IThirdPartyAuthorization thirdPartyAuth = new TokenAuthorization(
                          context.Request.Params["permission$accessToken"],
                          context.Request.Params["permission$tokenSecret"]);

                cred = new SignatureCredential("jb-us-seller_api1.paypal.com",
                        "WX4WTU3S8MY44S7F",
                        "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy");

                cred.ApplicationId = "APP-80W284485P519543T";
                cred.ThirdPartyAuthorization = thirdPartyAuth;
            }
            return cred;
        }
        /// <summary>
        /// Returns the credentials
        /// </summary>
        /// <returns></returns>
        private ICredential GetCredentials()
        {
            ICredential returnCredential = null;

            try
            {
                CredentialManager credentialMngr = CredentialManager.Instance;
                returnCredential = credentialMngr.GetCredentials(apiUsername);

                if (!string.IsNullOrEmpty(accessToken))
                {
                    IThirdPartyAuthorization toknAuthuthorization = new TokenAuthorization(accessToken, tokenSecret);

                    if (returnCredential is SignatureCredential)
                    {
                        SignatureCredential sigCred = (SignatureCredential)returnCredential;
                        sigCred.ThirdPartyAuthorization = toknAuthuthorization;
                    }
                    else if (returnCredential is CertificateCredential)
                    {
                        CertificateCredential certCred = (CertificateCredential)returnCredential;
                        certCred.ThirdPartyAuthorization = toknAuthuthorization;
                    }
                }
            }
            catch(System.Exception ex)
            {
                throw ex;
            }
            return returnCredential;
        }