/// <summary> /// Processing for 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 signGenerator = new OAuthGenerator(signCredential.UserName, signCredential.Password); signGenerator.setHTTPMethod(OAuthGenerator.HTTPMethod.POST); signGenerator.setToken(toknAuthorization.AccessToken); signGenerator.setTokenSecret(toknAuthorization.TokenSecret); string tokenTimeStamp = Timestamp; signGenerator.setTokenTimestamp(tokenTimeStamp); logger.Debug("token = " + toknAuthorization.AccessToken + " tokenSecret=" + toknAuthorization.TokenSecret + " uri=" + endpointURL); signGenerator.setRequestURI(endpointURL); //Compute Signature string sign = signGenerator.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_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; }
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.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]); }
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 GenerateHeaderStrategyWithoutToken() { SignatureHttpHeaderAuthStrategy signatureHttpHeaderAuthStrategy = new SignatureHttpHeaderAuthStrategy(Constants.APIEndpointNVP); signCredential = new SignatureCredential("testusername", "testpassword", "testsignature"); Dictionary<string, string> header = signatureHttpHeaderAuthStrategy.GenerateHeaderStrategy(signCredential); string username = header[BaseConstants.PayPalSecurityUserIdHeader]; string password = header[BaseConstants.PayPalSecurityPasswordHeader]; string sign = header[BaseConstants.PayPalSecuritySignatureHeader]; Assert.AreEqual("testusername", username); Assert.AreEqual("testpassword", password); Assert.AreEqual("testsignature", sign); }
public void GenerateHeaderStrategyWithoutToken() { signHttpHeaderAuthStrategy = new SignatureHttpHeaderAuthStrategy(UnitTestConstants.APIEndpointSOAP); signCredential = new SignatureCredential("testusername", "testpassword", "testsignature"); Dictionary<string, string> header = signHttpHeaderAuthStrategy.GenerateHeaderStrategy(signCredential); string username = header[BaseConstants.PAYPAL_SECURITY_USERID_HEADER]; string password = header[BaseConstants.PAYPAL_SECURITY_PASSWORD_HEADER]; string sign = header[BaseConstants.PAYPAL_SECURITY_SIGNATURE_HEADER]; Assert.AreEqual("testusername", username); Assert.AreEqual("testpassword", password); Assert.AreEqual("testsignature", sign); }
public void ObjectCreation() { SignatureCredential cred = new SignatureCredential(); cred.APIUsername = "******"; cred.APIPassword = "******"; cred.ApplicationID = "APP-1234ASDFG"; cred.APISignature = "Adsjsalkdsadsad.sdsadipoewirpoewr"; Assert.AreEqual("username_api1.paypal.com", cred.APIUsername); Assert.AreEqual("QWERRTYUIOP", cred.APIPassword); Assert.AreEqual("Adsjsalkdsadsad.sdsadipoewirpoewr", cred.APISignature); Assert.AreEqual("APP-1234ASDFG", cred.ApplicationID); }
public void GenerateHeaderStrategy() { signCredential = new SignatureCredential("testusername", "testpassword", "testsignature"); signSOAPHeaderAuthStrategy = new SignatureSOAPHeaderAuthStrategy(); string payload = signSOAPHeaderAuthStrategy.GenerateHeaderStrategy(signCredential); XmlDocument xmlDoc = GetXmlDocument(payload); XmlNodeList xmlNodeListUsername = xmlDoc.GetElementsByTagName("Username"); Assert.IsTrue(xmlNodeListUsername.Count > 0); Assert.AreEqual("testusername", xmlNodeListUsername[0].InnerXml); XmlNodeList xmlNodeListPassword = xmlDoc.GetElementsByTagName("Password"); Assert.IsTrue(xmlNodeListPassword.Count > 0); Assert.AreEqual("testpassword", xmlNodeListPassword[0].InnerXml); XmlNodeList xmlNodeListSignature = xmlDoc.GetElementsByTagName("Signature"); Assert.IsTrue(xmlNodeListSignature.Count > 0); Assert.AreEqual("testsignature", xmlNodeListSignature[0].InnerXml); }
public ICredential GetCredentials(string apiUserName) { if (apiUserName == null) { apiUserName = GetDefaultAccountName(); } if (this.cachedCredentials.ContainsKey(apiUserName)) { log.Debug("Returning cached credentials for " + apiUserName); return this.cachedCredentials[apiUserName]; } else { ICredential pro = null; ConfigManager configMgr = ConfigManager.Instance; Account acc = configMgr.GetAccount(apiUserName); if (acc == null) { throw new MissingCredentialException("Missing credentials for " + apiUserName); } if (!string.IsNullOrEmpty(acc.APICertificate)) { CertificateCredential cred = new CertificateCredential(); cred.APIUsername = acc.APIUsername; cred.APIPassword = acc.APIPassword; cred.CertificateFile = acc.APICertificate; cred.PrivateKeyPassword = acc.PrivateKeyPassword; cred.ApplicationID = acc.ApplicationId; cred.CertificateSubject = acc.CertificateSubject; pro = cred; } else { SignatureCredential cred = new SignatureCredential(); cred.APIUsername = acc.APIUsername; cred.APIPassword = acc.APIPassword; cred.APISignature = acc.APISignature; cred.ApplicationID = acc.ApplicationId; cred.SignatureSubject = acc.SignatureSubject; pro = cred; } this.cachedCredentials.Add(apiUserName, pro); return pro; } }
public void SignatureCredentialArgumentException() { signCredential = new SignatureCredential(null, null, null); }
public SignatureCredentialTest() { signCredential = new SignatureCredential("platfo_1255077030_biz_api1.gmail.com", "1255077037", "Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf"); }
/// <summary> /// Returns the API Credentials /// </summary> /// <param name="apiUserName"></param> /// <returns></returns> public ICredential GetCredentials(Dictionary<string, string> config, string apiUserName) { ICredential credential = null; Account accnt = GetAccount(config, apiUserName); if (accnt == null) { throw new MissingCredentialException("Missing credentials for " + apiUserName); } if (!string.IsNullOrEmpty(accnt.APICertificate)) { CertificateCredential certCredential = new CertificateCredential(accnt.APIUserName, accnt.APIPassword, accnt.APICertificate, accnt.PrivateKeyPassword); certCredential.ApplicationId = accnt.ApplicationId; if (!string.IsNullOrEmpty(accnt.CertificateSubject)) { SubjectAuthorization subAuthorization = new SubjectAuthorization(accnt.CertificateSubject); certCredential.ThirdPartyAuthorization = subAuthorization; } credential = certCredential; } else { SignatureCredential signCredential = new SignatureCredential(accnt.APIUserName, accnt.APIPassword, accnt.APISignature); signCredential.ApplicationId = accnt.ApplicationId; if (!string.IsNullOrEmpty(accnt.SignatureSubject)) { SubjectAuthorization subjectAuthorization = new SubjectAuthorization(accnt.SignatureSubject); signCredential.ThirdPartyAuthorization = subjectAuthorization; } credential = signCredential; } ValidateCredentials(credential); return credential; }
/// <summary> /// Validates the Signature Credentials /// </summary> /// <param name="apiCredentials"></param> private void Validate(SignatureCredential apiCredentials) { if (string.IsNullOrEmpty(apiCredentials.UserName)) { throw new InvalidCredentialException(BaseConstants.ErrorMessages.ErrorUserName); } if (string.IsNullOrEmpty(apiCredentials.Password)) { throw new InvalidCredentialException(BaseConstants.ErrorMessages.ErrorPassword); } if (string.IsNullOrEmpty(((SignatureCredential)apiCredentials).Signature)) { throw new InvalidCredentialException(BaseConstants.ErrorMessages.ErrorSignature); } }
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 API Credentials /// </summary> /// <param name="apiUserName"></param> /// <returns></returns> public ICredential GetCredentials(string apiUserName) { if (apiUserName == null) { apiUserName = GetDefaultAccountName(); } ICredential credential = null; ConfigManager configMngr = ConfigManager.Instance; Account accnt = configMngr.GetAccount(apiUserName); if (accnt == null) { throw new MissingCredentialException("Missing credentials for " + apiUserName); } if (!string.IsNullOrEmpty(accnt.APICertificate)) { CertificateCredential certCredential = new CertificateCredential(accnt.APIUsername, accnt.APIPassword, accnt.APICertificate, accnt.PrivateKeyPassword); certCredential.ApplicationID = accnt.ApplicationId; if (!string.IsNullOrEmpty(accnt.CertificateSubject)) { SubjectAuthorization subAuthorization = new SubjectAuthorization(accnt.CertificateSubject); certCredential.ThirdPartyAuthorization = subAuthorization; } credential = certCredential; } else { SignatureCredential signCredential = new SignatureCredential(accnt.APIUsername, accnt.APIPassword, accnt.APISignature); signCredential.ApplicationID = accnt.ApplicationId; if (!string.IsNullOrEmpty(accnt.SignatureSubject)) { SubjectAuthorization subjectAuthorization = new SubjectAuthorization(accnt.SignatureSubject); signCredential.ThirdPartyAuthorization = subjectAuthorization; } credential = signCredential; } ValidateCredentials(credential); return credential; }