public async Task <IActionResult> Authenticate([FromBody] AuthenticationParameters parameters) { var context = await _userManagerAuthentication.Get(parameters); if (context == null) { return(Ok(new AuthenticationContext())); } return(Ok(context)); }
public async Task <bool> ValidateAndExtract(HttpContext context, IUserManagerAuthentication userManagerAuthenticationManager, string token) { try { _logger.LogDebug("TokenValidator, ValidateAndExtract, Parameters token:{token}", token); var claims = GetClaims(token); if (!claims.Any()) { return(false); } var user = new TokenUser { Id = int.Parse(claims.First(x => x.Type == "id").Value), Type = Enum.Parse <UserType>(claims.First(x => x.Type == "type").Value) }; _logger.LogDebug("TokenValidator, ValidateAndExtract, User Id :{user}", user.Id); var userContext = await userManagerAuthenticationManager.Get(user.Id, user.Type); if (userContext == null) { _logger.LogDebug("User not exsits in the databas, user id: {id}", user.Id); return(false); } context.Items["User"] = new TokenUser { Id = userContext.UserId, Identifier = userContext.Identifier, Type = userContext.Type, }; return(true); } catch (Exception exception) { _logger.LogError(exception, exception.Message); return(false); } }