public FileServiceJwt VerifyJwt(AuthJwt auth) { // check signature // check IP var publicKey = this._configService.Get("JWTPublicKey"); throw new NotImplementedException(); }
public async Task <ActionResult <string> > Monitor(int count = 20) { var auth = new AuthJwt { IP = this.HttpContext.GetRemoteIPAddress().MapToIPv4().ToString(), Jwt = this.Request.Headers["Authorization"].ToArray().FirstOrDefault(a => a.StartsWith("Bearer "))?.Replace("Bearer ", string.Empty), }; var fileDTO = await this._fileAppService.Monitor(auth, count); return(Ok(fileDTO)); }
public async Task <FileServiceJwt> VerifyJwt(AuthJwt auth) { try { // check signature var publicKey = await this._configService.Get("JWTPublicKeys"); //var cer = new X509Certificate2(Convert.FromBase64String(publicKey)); var rsa = CertificateHelper.GetPublicKey(auth.Jwt, publicKey);// (RSA)(cer.PublicKey.Key); var validationParameters = new TokenValidationParameters { ValidateAudience = false, IssuerSigningKey = new RsaSecurityKey(rsa), ValidateIssuer = false, }; var result = new JwtSecurityTokenHandler().ValidateToken(auth.Jwt, validationParameters, out SecurityToken securityToken); var validateToken = securityToken as JwtSecurityToken; string scopeStr = validateToken.Claims.FirstOrDefault(c => c.Type == "scope")?.Value; string jti = validateToken.Claims.FirstOrDefault(c => c.Type == "jti")?.Value; string iss = validateToken.Claims.FirstOrDefault(c => c.Type == "iss")?.Value; ScopeDto scope = new ScopeDto(); if (!string.IsNullOrEmpty(scopeStr)) { scope = JsonConvert.DeserializeObject <ScopeDto>(scopeStr); } //LogHelper.Info($"Check ip: JWT->{scope.ip}, FileService->{auth.IP}"); //此处ip校验,在对部分域名使用vpn加速情况下,可能造成ip不一致,所以暂时去掉 /* * if (scope.ip != auth.IP && scope.ip != "127.0.0.1") * { * throw new UnauthorizedException(); * } */ VerifyJti(jti); return(new FileServiceJwt() { ExpireInDays = scope.fileExpireInDays, SiteId = scope.siteId, AppId = iss }); } catch (Exception ex) { LogHelper.Error(ex, ex.Message); throw new UnauthorizedException(); } }
public async Task <List <FileDto> > Monitor(AuthJwt authJwt, int count) { var jwtResult = await this._fileAuthService.VerifyJwt(authJwt); List <FileDto> result = new List <FileDto>(); var spec = new FileFilterSpecification(StorageType.Db); spec.ApplyPaging(1, count); var list = this._fileDomainService.GetList(spec); foreach (var item in list) { result.Add(new FileDto { FileKey = item.FileKey, SiteId = item.SiteId, CreationTime = item.CreationTime, ExpireTime = item.ExpireTime }); } return(result); }