コード例 #1
0
		/// <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);

		}
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public UserController(
     UserManager <ApplicationUser> userManager,
     AuthenticationTokenService authenticationTokenService
     )
 {
     _userManager = userManager;
     _authenticationTokenService = authenticationTokenService;
 }
コード例 #5
0
        public AuthenticationServiceStub CreateAuthenticationServiceStub()
        {
            AuthenticationTokenService service = new AuthenticationTokenService()
            {
                Url     = Settings.AuthenticationServiceUrl,
                Timeout = Settings.Timeout
            };

            return(new AuthenticationServiceStub(service));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 /// <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);
 }