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); }
public Action EnsureApplicationIsNotSubscribed(ApplicationInfo appInfo) { if (Convert.ToBoolean(appInfo.Metadata["authorised"])) { var subscriber = new ApplicationSubscriber(); subscriber.Unsubscribe(appInfo.Key, appInfo.Metadata["redirectUrl"].ToString(), appInfo.Metadata["scope"].ToString(), AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword); return(() => subscriber.Subscribe(appInfo.Key, appInfo.Metadata["redirectUrl"].ToString(), appInfo.Metadata["scope"].ToString(), AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword)); } return(() => { }); }
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)); }
private APITestFramework.Resources.PublicAPI.Authentication GetAndValidateOAuthCode(string appId, ApplicationType apptype, List <string> scope = null) { if (apptype == ApplicationType.SecondParty) { APITestFramework.Resources.PublicAPI.Authentication auth = oAuthAPI.GetCodeSuccess(appId, "code_direct", scopeList: scope); Assume.That(auth, Is.Not.Null, "Getting code from OAuth is not successful!"); Assume.That(auth.Error, Is.EqualTo(Enums.PublicAPIResultCode.Success.ToString()), "Getting code from OAuth is not successful!"); Assume.That(auth.Code, Is.Not.Null.And.Not.Empty, "Getting code from OAuth is not successful!"); return(auth); } var subscriber = new ApplicationSubscriber(); Assert.That(subscriber.Subscribe(appId, ApplicationSubscriber.DefaultRedirectUrl, FullScope, AuthenticationInfoProvider.Current.DefaultCompanyName, AuthenticationInfoProvider.Current.DefaultUserLogin, AuthenticationInfoProvider.Current.DefaultUserPassword), Is.EqualTo(AuthResponseCode.Success)); return(new APITestFramework.Resources.PublicAPI.Authentication { Code = subscriber.ResultOauthCode }); }