public async Task <ActionResult <string> > Sign(JwtPayloadDto jwtPayloadDto) { //{"siteId":"1","ip":"192.168.1.1","fileExpireInDays":"10","exp":1574681417,"iat":1574680817,"iss":"host","aud":"FileService"} //var payLoad = JsonConvert.DeserializeObject<Dictionary<string, object>>(Base64UrlEncoder.Decode(jwt)); await this._fileAuthService.VerifyComm100Platform( new AuthComm100Platform { SharedSecret = Request.Headers["Authorization"].ToArray().FirstOrDefault(a => a.StartsWith("Bearer "))?.Replace("Bearer ", string.Empty), IP = this.HttpContext.GetRemoteIPAddress().MapToIPv4().ToString(), }); return(await _fileAuthService.GenerateToken(jwtPayloadDto)); }
public async Task <string> GenerateToken(JwtPayloadDto jwtPayloadDto) { var rsaWithThumbprint = await _jwtCertificateService.GetPrivateKey(); var claims = new List <Claim> { new Claim("scope", JsonConvert.SerializeObject(jwtPayloadDto.scope)), new Claim("jti", Guid.NewGuid().ToString()), new Claim(JwtTokenConstants.Thumbprint, rsaWithThumbprint.Thumbprint), }; var iss = jwtPayloadDto.iss; var aud = "FileService"; var iat = DateTime.UtcNow; var exp = iat.AddMinutes(10); var key = new RsaSecurityKey(rsaWithThumbprint.Rsa.ExportParameters(true)); var creds = new SigningCredentials(key, SecurityAlgorithms.RsaSha256Signature); var payload = new JwtPayload(iss, aud, claims, null, exp, iat); var token = new JwtSecurityToken(new JwtHeader(creds), payload); return(new JwtSecurityTokenHandler().WriteToken(token)); }