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 void TestOauthStolenAppId(ApplicationType appType) { InitApiHelpers(appType); var defaultAppInfo = GetDefaultApplication(appType); using (var appInfo = AuthenticationInfoProvider.Current.Manager.GetApplication( new ApplicationSpecBuilder().ParameterEquals("type", appType.ToString()).ParameterContains("categories", "app_stolen"))) { // Oauth APITestFramework.Resources.PublicAPI.Authentication auth = oAuthAPI.GetCodeSuccess(appInfo.Key, "code_direct"); Assume.That(auth, Is.Not.Null, "Failed to parse the server's response"); if (appType == ApplicationType.SecondParty) { Assume.That(auth.Error, Is.EqualTo(Enums.PublicAPIAuthCode.Success.ToString()), auth.Message); // Access Token auth = tokenAPI.AccessTokenSuccess(appInfo.Key, "oauth_code", defaultAppInfo.Secret, auth.Code); Assert.That(auth, Is.Not.Null, "Failed to parse the server's response"); Assert.That(auth.Error, Is.EqualTo(Enums.PublicAPIAuthCode.SecretInvalid.ToString()), auth.Message); } else { Assert.That(auth.Error, Is.EqualTo(Enums.PublicAPIAuthCode.ResponseTypeInvalid.ToString()), "Wrong error message for oauth call for 3rd party app."); } } }
private APITestFramework.Resources.PublicAPI.Authentication Authenticate(string appId, string secret, ApplicationType apptype, List <string> scope = null) { APITestFramework.Resources.PublicAPI.Authentication auth = GetAndValidateOAuthCode(appId, apptype); auth = tokenAPI.AccessTokenSuccess(appId, "oauth_code", secret, auth.Code); Assume.That(auth, Is.Not.Null, "Getting an access token from TokenAPI is not successful!"); Assume.That(auth.Error, Is.EqualTo(Enums.PublicAPIResultCode.Success.ToString()), "Getting an access token from TokenAPI is not successful!"); Assume.That(auth.AccessToken, Is.Not.Null.And.Not.Empty, "Getting an access token from TokenAPI is not successful!"); return(auth); }
public void TestAuthenticationAPIs() { OAuthAPI api = new OAuthAPI(); TokenAPI tokenApi = new TokenAPI(); Authentication authentication = api.GetCodeSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "code_direct"); Assert.That(authentication, Is.Not.Null, "Cannot access to OAuth API"); authentication = tokenApi.AccessTokenSuccess(AuthenticationInfoProvider.Current.DefaultAppKey, "oauth_code", AuthenticationInfoProvider.Current.DefaultAppSecret, authentication.Code); Assert.That(authentication, Is.Not.Null, "Cannot access to Token API"); Assert.That(authentication.Error, Is.EqualTo(Enums.PublicAPIResultCode.Success.ToString()), "Getting token is not successful!"); Assert.That(authentication.AccessToken, Is.Not.Null.And.Not.Empty, "AccessToken is null or empty"); }
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)); }