public async Task <LoginServiceResult> Login(LoginServiceContract contract) { var user = await _userService.GetUser(contract.Login); var loginResult = GetLoginResult(contract, user); if (loginResult.Success) { await _userService.UpdateRefreshToken(user.Id, contract.RefreshToken); } return(loginResult); }
public void attachUserToContext(HttpContext context, IUserDbService service, string token) { try { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_jwtSettings.secretKey); tokenHandler.ValidateToken(token, new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = false, ValidateAudience = false, ClockSkew = TimeSpan.Zero }, out SecurityToken validatedToken ); var jwtToken = (JwtSecurityToken)validatedToken; var IdUser = int.Parse(jwtToken.Claims.First(x => x.Type == "IdUser").Value); context.Items["User"] = service.GetUser(IdUser); } catch { } }
public async Task <OrphanageDataModel.Persons.User> GetUser(int id) { return(await _userDBService.GetUser(id)); }