/// <summary> /// Initializes a new instance of the <see cref="Silanis.ESL.SDK.SessionService"/> class. /// </summary> /// <param name="apiToken">API token.</param> /// <param name="baseUrl">Base URL.</param> public SessionService (string apiToken, string baseUrl) { this.apiToken = apiToken; template = new UrlTemplate (baseUrl); authenticationService = new AuthenticationTokenService(new RestClient(apiToken), baseUrl); }
public void WhenTokenIsDifferent_ShouldReturnFalse(string correctToken, string sentToken) { //Arrange var user = new User() { AuthenticationToken = correctToken, AuthenticationTokenExpiration = DateTime.Now.Brasilia().AddDays(-5) }; var userList = new List <User>() { user }; var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(moq => moq.RepositoryBase.Get <User>( It.IsAny <Expression <Func <User, bool> > >(), It.IsAny <Func <IQueryable <User>, IOrderedQueryable <User> > >())) .Returns(userList.AsQueryable()); var service = new AuthenticationTokenService(mockUnitOfWork.Object); //Act var result = service.ValidateToken("", sentToken); //Assert Assert.NotNull(result); Assert.False(result.Status); }
public IWebServiceConnection Build() { IAuthenticationTokenService authService = new AuthenticationTokenService() { Url = AuthenticationServiceUrl }; AuthenticationStrategy strategy; switch (m_authStrategyType) { case AuthenticationStrategyType.Conservative: strategy = new ConservativeStrategy(authService, CredentialSource, m_authTokenType); break; case AuthenticationStrategyType.SettingsBased: strategy = new SettingsBasedStrategy(authService, CredentialSource, m_authTokenType); break; case AuthenticationStrategyType.Optimistic: strategy = new OptimisticStrategy(authService, CredentialSource, m_authTokenType); break; case AuthenticationStrategyType.Reauthenticating: strategy = new ReauthenticatingStrategy(authService, CredentialSource, m_authTokenType); break; default: strategy = new ReauthenticatingStrategy(authService, CredentialSource, m_authTokenType); break; } return(strategy); }
public UserController( UserManager <ApplicationUser> userManager, AuthenticationTokenService authenticationTokenService ) { _userManager = userManager; _authenticationTokenService = authenticationTokenService; }
public AuthenticationServiceStub CreateAuthenticationServiceStub() { AuthenticationTokenService service = new AuthenticationTokenService() { Url = Settings.AuthenticationServiceUrl, Timeout = Settings.Timeout }; return(new AuthenticationServiceStub(service)); }
private static void ValidateBasicAuthentication() { var authorization = WebOperationContext.Current?.IncomingRequest.Headers["Authorization"]; if (string.IsNullOrWhiteSpace(authorization)) { throw new WebFaultException(HttpStatusCode.Forbidden); } var basicAuth = new BasicAuth(authorization); var token = new AuthenticationTokenService().Authenticate(basicAuth.Creds); ValidateToken(token); }
public void WhenUserIsValid_ShouldAddToken() { //Arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(moq => moq.RepositoryBase.Edit(It.IsAny <User>())); mockUnitOfWork.Setup(moq => moq.Commit()); var service = new AuthenticationTokenService(mockUnitOfWork.Object); //Act var result = service.CreateAuthenticationToken(new User()); //Assert mockUnitOfWork.Verify(a => a.RepositoryBase.Edit(It.IsAny <User>()), Times.Once); mockUnitOfWork.Verify(a => a.Commit(), Times.Once); Assert.NotNull(result); Assert.Equal(6, result.Length); }
/// <summary> /// Initializes a new instance of the <see cref="Silanis.ESL.SDK.SessionService"/> class. /// </summary> /// <param name="apiToken">API token.</param> /// <param name="baseUrl">Base URL.</param> public SessionService(string apiToken, string baseUrl) { this.apiToken = apiToken; template = new UrlTemplate(baseUrl); authenticationService = new AuthenticationTokenService(new RestClient(apiToken), baseUrl); }