public void TestPublicAPIWithMultiAccounts() { isPublicAPILogin = PublicAuthentication.Authenticate(AuthenticationInfoProvider.Current.DefaultAppKey, AuthenticationInfoProvider.Current.DefaultAppSecret); Assert.IsTrue(isPublicAPILogin); Dictionary <string, object> parameters = new Dictionary <string, object>() { { "request_type", "1" } }; ReadResponseData <Partition> result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess <Partition>(parameters); Assert.NotNull(result); Assert.NotNull(result.Items); Assert.AreEqual(result.Items.Count, 1); Assert.AreEqual(result.Items[0].Id, AuthenticationInfoProvider.Current.DefaultPartition); isPublicAPILogin = PublicAuthentication.Authenticate(PublicAPIConfig.GetValueFromConfig("AppId2"), PublicAPIConfig.GetValueFromConfig("AppSecret2")); Assert.IsTrue(isPublicAPILogin); parameters = new Dictionary <string, object>() { { "request_type", "1" } }; result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess <Partition>(parameters); Assert.NotNull(result); Assert.NotNull(result.Items); Assert.AreEqual(result.Items.Count, 1); Assert.AreEqual(result.Items[0].Id, PublicAPIConfig.GetValueFromConfig("Partition2")); }
/// <summary> /// /// </summary> /// <param name="code">The authorization code we get from service when user provides valid credentials. It is sent to the service to get the access token.</param> /// <returns></returns> public ActionResult GetAccessToken(string code) { string callbackUrl = Url.Action("GetAccessToken", "Oauth2", null, Request.Url.Scheme, Request.Url.Host); ILogger Logger = new PepperiLogger(); PublicAuthentication PublicAuthentication = new PublicAuthentication(Logger, Settings.OauthBaseUri, Settings.PublicApplication_ConsumerKey, Settings.PublicApplication_ConsumerSecret); Oauth2Token Oauth2Token = PublicAuthentication.GetAccessTokenByAuthorizationCode(code, callbackUrl, "READ", new TokenRepository(this.Session)); return(RedirectToAction("Transactions", "Transaction")); }
public ActionResult GetAuthorizationCode() { string callbackUrl = Url.Action("GetAccessToken", "Oauth2", null, Request.Url.Scheme, Request.Url.Host); ILogger Logger = new PepperiLogger(); PublicAuthentication PublicAuthentication = new PublicAuthentication(Logger, Settings.OauthBaseUri, Settings.PublicApplication_ConsumerKey, Settings.PublicApplication_ConsumerSecret); string AuthorizationUrl = PublicAuthentication.GetAuthorizationUrl(callbackUrl, "READ"); return(Redirect(AuthorizationUrl)); }
internal static ApiClient GetAapiClient_ForPublicApplication(HttpSessionStateBase Session, ILogger Logger) { string ApiBaseUri = Settings.ApiBaseUri; string OauthBaseUri = Settings.OauthBaseUri; string PublicApplication_ConsumerKey = Settings.PublicApplication_ConsumerKey; string PublicApplication_ConsumerSecret = Settings.PublicApplication_ConsumerSecret; TokenRepository Oauth2TokenRepository = new TokenRepository(Session); Oauth2Token Oauth2Token = Oauth2TokenRepository.GetOauth2Token(); var IAuthentication = new PublicAuthentication(Logger, OauthBaseUri, PublicApplication_ConsumerKey, PublicApplication_ConsumerSecret, Oauth2Token, Oauth2TokenRepository); ApiClient ApiClient = new ApiClient(ApiBaseUri, IAuthentication, Logger); return(ApiClient); }
public void TestPublicAPILoginFail() { isPublicAPILogin = PublicAuthentication.Authenticate(AuthenticationInfoProvider.Current.DefaultAppKey, Util.GetUniqueString(16)); Assert.IsFalse(isPublicAPILogin); }