Exemplo n.º 1
0
        public async void ValidateIfGeneratedAuthCodeIsStored()
        {
            var authCode = await _AuthCodeService.GenerateAuthCodeAsync(new ClaimsPrincipal());

            var result = await _AuthCodeService.GetClaimsByAuthCodeAsync(authCode);

            Assert.NotNull(result);
        }
        public async Task <IActionResult> ExecuteAsync(HttpContext httpContext, TokenAuthorisationArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var claims = await _AuthCodeService.GetClaimsByAuthCodeAsync(args.Code);

            if (claims == null)
            {
                return(new UnauthorizedResult());
            }

            //TODO: add sliding expiry time to distributed cache
            await _AuthCodeService.RevokeAuthCodeAsync(args.Code);

            var jwtToken = _JwtService.Generate(claims);

            return(new OkObjectResult(new
            {
                Token = jwtToken
            }));
        }