private void InitScopeAdapter(string scope, ApplicationType appType) { appInfo = GetDefaultApplication(appType); var connection = new PublicAPIConnection(appInfo.Key, appInfo.Secret); var subscriber = new ApplicationSubscriber(); Assume.That(subscriber.Subscribe(appInfo.Key, appInfo.Metadata["redirectUrl"].ToString(), scope, AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword), Is.EqualTo(AuthResponseCode.Success)); _testCleanupActions.Add(() => subscriber.Unsubscribe(appInfo.Key, appInfo.Metadata["redirectUrl"].ToString(), scope, AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword)); var tokenApi = new TokenAPI { AccessHelper = new PublicAPIConnection(appInfo.Key, appInfo.Secret) }; var tokenResponse = tokenApi.AccessTokenSuccess(appInfo.Key, "oauth_code", appInfo.Secret, subscriber.ResultOauthCode); Assume.That(tokenResponse.AccessToken, Is.Not.Null); connection.Authentication.Token = tokenResponse.AccessToken; adapter = PublicApiAdapter.CreateAdapter(connection, appInfo.Company.Partition); }
private void InitNoScopeAdapters() { var secondPartyAppInfo = GetDefaultApplication(ApplicationType.SecondParty); var secondPartyConnection = new PublicAPIConnection(secondPartyAppInfo.Key, secondPartyAppInfo.Secret); Dictionary <string, string> oauthParams = new Dictionary <string, string>(); oauthParams.Add("scope", string.Empty); oauthParams.Add("app_id", secondPartyAppInfo.Key); oauthParams.Add("response_type", "code_direct"); secondPartyConnection.Authentication.Authenticate(oauthParams); _secondPartyApplicationAdapter = PublicApiAdapter.CreateAdapter(secondPartyConnection, secondPartyAppInfo.Company.Partition); var thirdPartyAppInfo = GetDefaultApplication(ApplicationType.ThirdParty); var thirdPartyConnection = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret); var subscriber = new ApplicationSubscriber(); Assume.That(subscriber.Subscribe(thirdPartyAppInfo.Key, thirdPartyAppInfo.Metadata["redirectUrl"].ToString(), "client_d", AuthenticationInfoProvider.Current.DefaultCompanyName, // client_d does not affect read/write operations. We use it as a workaround for empty scope AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword), Is.EqualTo(AuthResponseCode.Success), "Couldn't get oauth code for 3rd party application"); var tokenApi = new TokenAPI { AccessHelper = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret) }; var tokenResponse = tokenApi.AccessTokenSuccess(thirdPartyAppInfo.Key, "oauth_code", thirdPartyAppInfo.Secret, subscriber.ResultOauthCode); Assume.That(tokenResponse.AccessToken, Is.Not.Null, "get token request for 3rd party application was not successful"); thirdPartyConnection.Authentication.Token = tokenResponse.AccessToken; _thirdPartyApplicationAdapter = PublicApiAdapter.CreateAdapter(thirdPartyConnection, thirdPartyAppInfo.Company.Partition); }
private PublicApiAdapter CreateSecondPartyAppAdapter(bool isReadApp) { var secondPartyAppInfo = GetDefaultApplication(ApplicationType.SecondParty, isReadApp); var secondPartyConnection = new PublicAPIConnection(secondPartyAppInfo.Key, secondPartyAppInfo.Secret); Dictionary <string, string> oauthParams = new Dictionary <string, string>(); oauthParams.Add("scope", isReadApp ? ReadOnlyScope : WriteOnlyScope); oauthParams.Add("app_id", secondPartyAppInfo.Key); oauthParams.Add("response_type", "code_direct"); secondPartyConnection.Authentication.Authenticate(oauthParams); return(PublicApiAdapter.CreateAdapter(secondPartyConnection, secondPartyAppInfo.Company.Partition)); }
public void TestSearchCondition(string requestType) { Dictionary <string, object> urlParameters = new Dictionary <string, object>(); if (requestType != null) { urlParameters[PartitionApiFields.RequestType] = requestType; } PublicAPIConnection connection = new PublicAPIConnection(singleCompanyAppInfo.Key, singleCompanyAppInfo.Secret); ReadResponseData <Partition> result = PublicApiAdapter.CreateAdapter(connection, singleCompanyAppInfo.Company.Partition).ReadSuccess <Partition>(urlParameters); Assert.That(result, MustBe.ReadSuccess(1), string.Format(Enums.Message.READ_RESOURCE_FAILED, "Partition")); }
private void PerformReadInvalidContentInputTest(string contentTypeHeaderValue, int expectedCode) { var connection = PreparePublicApiConnection(contentTypeHeaderValue); var adapter = PublicApiAdapter.CreateAdapter(connection, AuthenticationInfoProvider.Current.DefaultPartition); var readParameters = new Dictionary <string, object> { ["partition"] = AuthenticationInfoProvider.Current.DefaultPartition, ["condition"] = "Client.P_Id=10001" }; var res = adapter.ReadFail <Client>(readParameters); Assert.That(res?.Code, Is.EqualTo(expectedCode)); }
private void PerformUpdateInvalidCharSetInputTest(string contentTypeHeaderValue, int expectedCode, string clientId) { var connection = PreparePublicApiConnection(contentTypeHeaderValue); var adapter = PublicApiAdapter.CreateAdapter(connection, AuthenticationInfoProvider.Current.DefaultPartition); var clientItem = new Client { Id = clientId, Name = "TestClient" + clientId }; var res = adapter.WriteFail <Client>(clientItem, null); Assert.That(res?.Code, Is.EqualTo(expectedCode)); }
private PublicApiAdapter CreateThirdPartyAppAdapter(bool isReadApp) { var thirdPartyAppInfo = GetDefaultApplication(ApplicationType.ThirdParty, isReadApp); var thirdPartyConnection = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret); var subscriber = new ApplicationSubscriber(); Assume.That(subscriber.Subscribe(thirdPartyAppInfo.Key, thirdPartyAppInfo.Metadata["redirectUrl"].ToString(), isReadApp ? ReadOnlyScope : WriteOnlyScope, AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword), Is.EqualTo(AuthResponseCode.Success), "Couldn't get oauth code for 3rd party application"); var tokenApi = new TokenAPI { AccessHelper = new PublicAPIConnection(thirdPartyAppInfo.Key, thirdPartyAppInfo.Secret) }; var tokenResponse = tokenApi.AccessTokenSuccess(thirdPartyAppInfo.Key, "oauth_code", thirdPartyAppInfo.Secret, subscriber.ResultOauthCode); Assume.That(tokenResponse.AccessToken, Is.Not.Null, "get token request for 3rd party application was not successful"); thirdPartyConnection.Authentication.Token = tokenResponse.AccessToken; return(PublicApiAdapter.CreateAdapter(thirdPartyConnection, thirdPartyAppInfo.Company.Partition)); }