Esempio n. 1
0
        public async Task <IActionResult> Get(int userId)
        {
            string accessToken = User.FindFirst("access_token")?.Value;
            var    currentUser = HttpContext.User;

            if (currentUser.HasClaim(c => c.Type == "UserId"))
            {
                int tokenUserId = int.Parse(currentUser.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
                Console.Out.WriteLine("Token user id " + tokenUserId);
                Console.Out.WriteLine("User id : " + userId);
                if (tokenUserId != userId)
                {
                    return(StatusCode(StatusCodes.Status401Unauthorized, Response <string> .Failure("Unauthorized access")));
                }
            }

            return(await HandleComputationFailure(_workoutService.GetByUser(userId)));
        }