private async Task <OrangeRocklandAuthToken> logIn() { LOGGER.Debug("Logging in to Orange & Rockland as {0}", username); OrangeRocklandAuthToken authToken = await client.authentication.submitCredentials(username, password); LOGGER.Debug("Logged into Orange & Rockland"); LOGGER.Trace($"ORU auth token: {authToken}"); return(authToken); }
public async void SubmitCredentials() { var tokenExchangeUriResponse = A.Fake <HttpResponseMessage>(); var authTokenResponse = A.Fake <HttpResponseMessage>(); var sessionActivationResponse = A.Fake <HttpResponseMessage>(); string credentialsRequestBody = null; var tokenExchangeUriResponeBody = new Dictionary <string, object> { { "login", true }, { "newDevice", false }, { "authRedirectUrl", "https://apps.coned.com/ORMyAccount/Forms/DcxLogin.aspx?params=abcdefg" }, { "noMfa", false }, { "legacyLockout", false } }; A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> ._)).ReturnsLazily(async call => { credentialsRequestBody = await call.Arguments[0].As <HttpRequestMessage>().Content.ReadAsStringAsync(); return(tokenExchangeUriResponse); }).Once().Then .Returns(authTokenResponse).Once().Then .Returns(sessionActivationResponse).Once(); A.CallTo(() => contentHandlers.ReadContentAsJson <IDictionary <string, object> >(tokenExchangeUriResponse)) .Returns(tokenExchangeUriResponeBody); var cookieContainer = new CookieContainer(); cookieContainer.Add(new Uri("https://apps.coned.com/"), new Cookie("LogCOOKPl95FnjAT", "hargle")); A.CallTo(() => apiClient.Cookies).Returns(cookieContainer); OrangeRocklandAuthToken actual = await authClient.SubmitCredentials("user", "pass"); actual.LogInCookie.Should().Be("hargle"); A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> .That.Matches(message => message.Method == HttpMethod.Post && message.RequestUri.ToString().Equals("https://www.oru.com/sitecore/api/ssc/ConEd-Cms-Services-Controllers-Okta/User/0/Login") ))).MustHaveHappened(); A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> .That.Matches(message => message.Method == HttpMethod.Get && message.RequestUri.ToString().Equals("https://apps.coned.com/ORMyAccount/Forms/DcxLogin.aspx?params=abcdefg") ))).MustHaveHappened(); A.CallTo(() => httpMessageHander.SendAsync(A <HttpRequestMessage> .That.Matches(message => message.Method == HttpMethod.Get && message.RequestUri.ToString().Equals("https://apps.coned.com/ORMyAccount/Forms/System/accountStatus.aspx") ))).MustHaveHappened(); credentialsRequestBody.Should().Be("{" + "\"LoginEmail\":\"user\"," + "\"LoginPassword\":\"pass\"," + "\"LoginRememberMe\":false," + "\"ReturnUrl\":\"\"" + "}"); }
public async Task <OrangeRocklandAuthToken> submitCredentials(string username, string password) { Uri tokenExchangeUri = await fetchTokenExchangeUriWithCredentials(username, password); OrangeRocklandAuthToken authToken = await fetchAuthToken(tokenExchangeUri); await activateSession(); return(authToken); }
public async Task logOut() { if (_authToken != null) { try { await client.authentication.logOut(); } catch (OrangeRocklandException) { //proceed even if log out fails, because what else can we do? } } _authToken = null; username = null; password = null; }
public async void GetAuthToken() { var token = new OrangeRocklandAuthToken(); var tokenTask = Task.FromResult(token); A.CallTo(() => authClient.SubmitCredentials(A <string> ._, A <string> ._)) .Returns(tokenTask); orangeRocklandAuthenticationService.Username = "******"; orangeRocklandAuthenticationService.Password = "******"; OrangeRocklandAuthToken actual = await orangeRocklandAuthenticationService.GetAuthToken(); actual.Should().BeSameAs(token); A.CallTo(() => authClient.SubmitCredentials("user", "pass")) .MustHaveHappened(Repeated.Exactly.Once); actual = await orangeRocklandAuthenticationService.GetAuthToken(); actual.Should().BeSameAs(token); A.CallTo(() => authClient.SubmitCredentials("user", "pass")) .MustHaveHappened(Repeated.Exactly.Once); }
public async Task <OrangeRocklandAuthToken> getAuthToken() { return(_authToken ?? (_authToken = await logIn())); }