public async Task <IActionResult> CreateUserTasksForGraduatingUsers(int withinAmountOfMonths) { // First check if worker service is trying to execute method to prevent internal server error. bool isAllowed = HttpContext.User.HasClaim("client_role", Defaults.Roles.BackendApplication); if (isAllowed == false) { User currentUser = await HttpContext.GetContextUser(userService) .ConfigureAwait(false); if (currentUser.Role.Name == Defaults.Roles.Administrator) { isAllowed = true; } } if (isAllowed) { List <UserTask> userTasks = await userTaskService.GetAllOpenGraduateUserTasks(withinAmountOfMonths); return(Ok(userTasks)); } return(Forbid()); }