public override Task <TokenResponse> Token(TokenRequst request, ServerCallContext context) { if (string.IsNullOrEmpty(request.Name)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名不能为空")); } if (string.IsNullOrEmpty(request.Password)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "密码不能为空")); } request.Password = request.Password.Get32MD5One(); var sysUser = _sysUser.SingleOrDefault(item => item.UserName == request.Name && item.Password == request.Password); if (sysUser == null) { throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名密码错误")); } var appConfig = new Ketchup.Zero.Application.Config.AppConfig(); return(Task.FromResult(new TokenResponse() { AccessToken = GenerateToken(appConfig), Expired = appConfig.Zero.AuthExpired, UserName = sysUser.UserName, RoleId = sysUser.RoleId, UserId = sysUser.Id })); }
public async Task <object> GetToken(TokenRequst request) { var client = await _clientProvider.FindGrpcClient <Auth.AuthClient>("zero"); var user = await client.LoginAsync(request); var config = new AppConfig(); var token = new JwtSecurityToken( audience: config.Gateway.Key, claims: new[] { new Claim(ClaimTypes.Sid, user.UserId.ToString()), new Claim(ClaimTypes.Name, user.UserName), new Claim(ClaimTypes.Role, user.RoleId.ToString()) }, issuer: config.Gateway.Key, notBefore: DateTime.Now, expires: DateTime.Now.AddSeconds(7200), signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config.Gateway.Secret)), SecurityAlgorithms.HmacSha256) ); return(new KetchupResponse(new { AccessToken = new JwtSecurityTokenHandler().WriteToken(token), UserId = user.UserId, UserName = user.UserName, Expired = config.Gateway.AuthExpired, RoleId = user.RoleId })); }
public override Task <TokenResponse> Login(TokenRequst request, ServerCallContext context) { if (string.IsNullOrEmpty(request.Name)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名不能为空")); } if (string.IsNullOrEmpty(request.Password)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "密码不能为空")); } request.Password = request.Password.Get32MD5One(); var sysUser = _sysUser.SingleOrDefault(item => item.UserName == request.Name && item.Password == request.Password); if (sysUser == null) { throw new RpcException(new Status(StatusCode.InvalidArgument, "用户名密码错误")); } return(Task.FromResult(new TokenResponse() { UserName = sysUser.UserName, RoleId = sysUser.RoleId, UserId = sysUser.Id })); }
public async Task <object> GetToken(TokenRequst request) { var client = await _clientProvider.FindGrpcClient <Auth.AuthClient>("zero"); var result = await client.TokenAsync(request); return(new KetchupReponse(result)); }