Ejemplo n.º 1
0
        public async Task ValidateIfAuthCodeIsRevokedCorrectly()
        {
            var authCode = await _AuthCodeService.GenerateAuthCodeAsync(new ClaimsPrincipal());

            await _AuthCodeService.RevokeAuthCodeAsync(authCode);

            var result = await _AuthCodeService.GetClaimsByAuthCodeAsync(authCode);

            Assert.Null(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
            }));
        }