示例#1
0
        /// <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>
        /// Returns the credentials
        /// </summary>
        /// <returns></returns>
        private ICredential GetCredentials()
        {
            ICredential returnCredential = null;

            try
            {
                CredentialManager credentialMngr = CredentialManager.Instance;
                returnCredential = credentialMngr.GetCredentials(this.config, 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);
        }
        /// <summary>
        /// Processing TokenAuthorization} using SignatureCredential
        /// </summary>
        /// <param name="signCredential"></param>
        /// <param name="toknAuthorization"></param>
        /// <returns></returns>
        protected internal override Dictionary <string, string> ProcessTokenAuthorization(
            SignatureCredential signCredential, TokenAuthorization toknAuthorization)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            try
            {
                OAuthGenerator sigGenerator = new OAuthGenerator(signCredential.UserName, signCredential.Password);
                sigGenerator.setHTTPMethod(OAuthGenerator.HTTPMethod.POST);
                sigGenerator.setToken(toknAuthorization.AccessToken);
                sigGenerator.setTokenSecret(toknAuthorization.TokenSecret);
                string tokenTimeStamp = Timestamp;
                sigGenerator.setTokenTimestamp(tokenTimeStamp);
                logger.Debug("token = " + toknAuthorization.AccessToken + " tokenSecret=" + toknAuthorization.TokenSecret + " uri=" + endpointURL);
                sigGenerator.setRequestURI(endpointURL);

                //Compute Signature
                string sign = sigGenerator.ComputeSignature();
                logger.Debug("Permissions signature: " + sign);
                string authorization = "token=" + toknAuthorization.AccessToken + ",signature=" + sign + ",timestamp=" + tokenTimeStamp;
                logger.Debug("Authorization string: " + authorization);
                headers.Add(BaseConstants.PAYPAL_AUTHORIZATION_PLATFORM_HEADER, authorization);
            }
            catch (OAuthException ae)
            {
                throw ae;
            }
            return(headers);
        }
示例#4
0
        public void ThirdPartyAuthorizationTestForToken()
        {
            IThirdPartyAuthorization thirdPartyAuthorization = new TokenAuthorization(Constants.AccessToken, Constants.TokenSecret);

            certCredential.ThirdPartyAuthorization = thirdPartyAuthorization;
            Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).AccessToken, Constants.AccessToken);
            Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).AccessTokenSecret, Constants.TokenSecret);
        }
示例#5
0
        public void ThirdPartyAuthorizationForToken()
        {
            IThirdPartyAuthorization thirdPartyAuthorization = new TokenAuthorization(UnitTestConstants.AccessToken, UnitTestConstants.TokenSecret);

            signCredential.ThirdPartyAuthorization = thirdPartyAuthorization;
            Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).AccessToken, UnitTestConstants.AccessToken);
            Assert.AreEqual(((TokenAuthorization)thirdPartyAuthorization).TokenSecret, UnitTestConstants.TokenSecret);
        }
示例#6
0
        /// <summary>
        /// Gets the signature credential.<br/>
        /// The credential combines accessToken, accessTokenSecret, apiUsername, apiPassword, ApiSignature and ApplicationId
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        /// <param name="accessTokenSecret">The access token secret.</param>
        /// <returns></returns>
        private SignatureCredential GetSignatureCredential(string accessToken, string accessTokenSecret)
        {
            TokenAuthorization tokenAuthorization = new TokenAuthorization(accessToken, accessTokenSecret);

            return(new SignatureCredential(Config.ApiUsername, Config.ApiPassword, Config.ApiSignature)
            {
                ApplicationId = Config.ApplicationId,
                ThirdPartyAuthorization = tokenAuthorization
            });
        }
        public void GenerateHeaderStrategyWithToken()
        {
            certHttpHeaderAuthStrategy = new CertificateHttpHeaderAuthStrategy(UnitTestConstants.APIEndpointSOAP);
            TokenAuthorization          toknAuthorization = new TokenAuthorization(UnitTestConstants.AccessToken, UnitTestConstants.TokenSecret);
            CertificateCredential       certCredential    = new CertificateCredential("testusername", "testpassword", "sdk-cert.p12", "KJAERUGBLVF6Y", toknAuthorization);
            Dictionary <string, string> header            = certHttpHeaderAuthStrategy.GenerateHeaderStrategy(certCredential);
            string authHeader = header[BaseConstants.PAYPAL_AUTHORIZATION_MERCHANT_HEADER];

            string[] headers = authHeader.Split(',');
            Assert.AreEqual("token=" + UnitTestConstants.AccessToken, headers[0]);
        }
示例#8
0
        public void GetPayloadEndpointWithoutTokenTest()
        {
            platformAPIHandler = new PlatformAPICallPreHandler(ConfigManager.Instance.GetProperties(), "payload", "servicename", "method", Constants.APIUserName, "accessToken", "tokenSecret");
            Assert.AreEqual("https://svcs.sandbox.paypal.com/servicename/method", platformAPIHandler.GetEndpoint());
            Assert.AreEqual("payload", platformAPIHandler.GetPayload());
            SignatureCredential signatureCredential = (SignatureCredential)platformAPIHandler.GetCredential();
            TokenAuthorization  thirdAuth           = (TokenAuthorization)signatureCredential.ThirdPartyAuthorization;

            Assert.AreEqual("accessToken", thirdAuth.AccessToken);
            Assert.AreEqual("tokenSecret", thirdAuth.AccessTokenSecret);
        }
示例#9
0
        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()
        {
            signHttpHeaderAuthStrategy = new SignatureHttpHeaderAuthStrategy(Constants.APIEndpointSOAP);
            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.PayPalAuthorizationMerchantHeader];

            string[] headers = authHeader.Split(',');
            Assert.AreEqual("token=" + Constants.AccessToken, headers[0]);
        }
示例#11
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(UnitTestConstants.APIEndpointNVP);
            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_PLATFORM_HEADER];

            string[] headers = authHeader.Split(',');
            Assert.AreEqual("token=" + UnitTestConstants.AccessToken, headers[0]);
        }
        public void GenerateHeaderStrategyWithTokenTest()
        {
            certHttpHeaderAuthStrategy = new CertificateHttpHeaderAuthStrategy(Constants.APIEndpointSOAP);
            TokenAuthorization toknAuthorization = new TokenAuthorization(Constants.AccessToken, Constants.TokenSecret);

            certCredential = new CertificateCredential("testusername", "testpassword", "sdk-cert.p12", "KJAERUGBLVF6Y", toknAuthorization);
            Dictionary <string, string> header = certHttpHeaderAuthStrategy.GenerateHeaderStrategy(certCredential);
            string authHeader = header[BaseConstants.PayPalAuthorizationPlatformHeader];

            string[] headers = authHeader.Split(',');
            Assert.AreEqual("token=" + Constants.AccessToken, headers[0]);
        }
示例#14
0
        // Config testing method requires internet and actually the knauf lookbook server
        public async Task configEqualsCheck()
        {
            string collectionIdentifier = "lookbook";
            AuthenticationHeaderValue authorizationHeader = await TokenAuthorization.GetAuthHeaderValue("*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login");

            IonConfig config = new IonConfig("https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier, "default", authorizationHeader, 120, 100, false);

            string collectionIdentifier2 = "lookbook";
            AuthenticationHeaderValue authorizationHeader2 = await TokenAuthorization.GetAuthHeaderValue("*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login");

            IonConfig config2 = new IonConfig("https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier2, "default", authorizationHeader2, 120, 100, false);

            Assert.IsTrue(config2.Equals(config));
        }
示例#15
0
        public async Task <IonConfig> loginAsync()
        {
            if (!_loggedIn)
            {
                String collectionIdentifier = "lookbook";

                AuthenticationHeaderValue authorizationHeader = await TokenAuthorization.GetAuthHeaderValue("*****@*****.**", "Jdt9y9qHt3", "https://lookbook-dev.anfema.com/client/v1/login");

                // Or using BasicAuth
                //AuthenticationHeaderValue authorizationHeader = BasicAuth.GetAuthHeaderValue( "*****@*****.**", "Jdt9y9qHt3" );

                IonConfig config = new IonConfig("https://lookbook-dev.anfema.com/client/v1/", "de_DE", collectionIdentifier, "default", authorizationHeader, 120, 100, false);

                // Only testing purpose TODO: remove
                _ampConfig = config;

                // Set the loggedIn bool
                _loggedIn = authorizationHeader != null;

                return(config);
            }

            return(_ampConfig);
        }
        /// <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 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 ArgumentExceptionTest()
 {
     TokenAuthorization toknAuthorization = new TokenAuthorization(null, null);
 }
示例#19
0
 public void ArgumentExceptionTest()
 {
     TokenAuthorization toknAuthorization = new TokenAuthorization(null, null);
 }
 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);
 }
 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()
 {
     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]);
 }
示例#23
0
 /// <summary>
 /// Process Token Authorization based on API format
 /// </summary>
 /// <param name="signCredential"></param>
 /// <param name="tokenAuthorize"></param>
 /// <returns></returns>
 protected internal abstract Dictionary <string, string> ProcessTokenAuthorization(SignatureCredential signCredential, TokenAuthorization tokenAuthorize);
 /// <summary>
 ///  Process Token Authorization based on API format
 /// </summary>
 /// <param name="certCredential"></param>
 /// <param name="tokenAuthorize"></param>
 /// <returns></returns>
 protected abstract Dictionary <string, string> ProcessTokenAuthorization(CertificateCredential certCredential, TokenAuthorization tokenAuthorize);
 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);
 }