Exemplo n.º 1
0
        private void CreateDefaultTokenServiceInstance()
        {
            _random = new Random();
            var tokenGenerator = Generator
                                 .For <TokenRefresh>()
                                 .For(x => x.Id)
                                 .ChooseFrom(Guid.NewGuid())
                                 .For(x => x.CreatorId)
                                 .ChooseFrom(Guid.NewGuid())
                                 .For(x => x.Token)
                                 .ChooseFrom(RandomString(20))
                                 .For(x => x.CreatedDate)
                                 .ChooseFrom(DateTime.Now);

            _fakeTokens = tokenGenerator.Generate(10).ToList();

            _tokenRepoMock = new Mock <ITokenRefreshRepository>();
            _tokenRepoMock.Setup(s => s.GetRefreshTokenByIpAddress(RandomString(10), default(CancellationToken))).ReturnsAsync(_fakeTokens);
            _tokenRepoMock.Setup(s => s.GetByIdAsync(It.IsAny <Guid>(), default(CancellationToken))).ReturnsAsync(_fakeTokens[0]);
            _tokenRepoMock.Setup(s => s.AddAsync(It.IsAny <TokenRefresh>(), default(CancellationToken)));
            _tokenRepoMock.Setup(s => s.UpdateAsync(It.IsAny <Guid>(), It.IsAny <TokenRefresh>(), default(CancellationToken)));
            _tokenRepoMock.Setup(s => s.RemoveAsync(It.IsAny <Guid>(), default(CancellationToken)));
            _tokenRepoMock.Setup(s => s.GetRefreshTokenByToken(RandomString(10), default(CancellationToken))).ReturnsAsync(_fakeTokens);
            _tokenRepoMock.Setup(s => s.GetRefreshTokenByUserId(It.IsAny <Guid>(), default(CancellationToken))).ReturnsAsync(_fakeTokens);



            _refreshTokenRepositry = _tokenRepoMock.Object;
            _tokenService          = new TokenRefreshService(_refreshTokenRepositry);
        }
Exemplo n.º 2
0
 public TokenController(SignInManager <ApplicationUser> signinManager,
                        UserManager <ApplicationUser> userManager,
                        IOptions <TokenProviderOptions> options,
                        TokenRefreshService tokenRefreshService)
 {
     _tokenRefreshService = tokenRefreshService;
     _options             = options.Value;
     _userManager         = userManager;
     _signinManager       = signinManager;
 }
        public IHttpActionResult Refresh([FromBody] TokenRefreshResponseDTO token)
        {
            TokenRefreshService service = new TokenRefreshService(token);

            var response = service.RefreshService();

            if (response.isSuccessful == false)
            {
                return(Content(HttpStatusCode.BadRequest, response));
            }

            return(Ok(response));
        }