小编Dmi*_*huk的帖子

.NET Core JWE:没有“cty”标头

我使用以下代码来发行我的 JWE:

var signCreds = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:SigningKey"])), SecurityAlgorithms.HmacSha256);
var encryptionCreds = new EncryptingCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:Encryptionkey"])), SecurityAlgorithms.Aes128KW, SecurityAlgorithms.Aes128CbcHmacSha256);

var handler = new JwtSecurityTokenHandler();


var jwtSecurityToken = handler.CreateJwtSecurityToken(
  Configuration["Jwt:Issuer"],
  Configuration["Jwt:Audience"],
  new ClaimsIdentity(claims),
  DateTime.UtcNow,
  expiresIn,
  DateTime.UtcNow,
  signCreds,
  encryptionCreds);
Run Code Online (Sandbox Code Playgroud)

但它没有指定令牌的“cty”标头 - 仅指定 alg、enc 和typ。如果我理解正确,则必须为加密的 JWT 设置标头,因此由于标头缺失,我在解析 golang 中的令牌时遇到问题。

我还尝试了以下几种方式来发行JWE:

var signCreds = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:SigningKey"])), SecurityAlgorithms.HmacSha256);
var encryptionCreds = new EncryptingCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:Encryptionkey"])), SecurityAlgorithms.Aes128KW, SecurityAlgorithms.Aes128CbcHmacSha256);

var handler = new JwtSecurityTokenHandler();

var tokenDescriptor1 = new SecurityTokenDescriptor
  {
     Audience = "you",
     Issuer = "me",
     Subject = new …
Run Code Online (Sandbox Code Playgroud)

.net c# jwt bearer-token jwe

6
推荐指数
1
解决办法
1118
查看次数

EF Core DDD 多对多

我正在尝试使用 EF Core 遵循 DDD,在我的模型中,我有以下内容:

    private List<TeamPerson> _personLinks;
    
    public IReadOnlyCollection<TeamPerson> PersonLinks => _personLinks?.ToList().AsReadOnly();

    public IReadOnlyCollection<Person> Members => _personLinks?.Select(l => l.Person).ToList().AsReadOnly();
Run Code Online (Sandbox Code Playgroud)

我想封装 Team 和 Person 模型之间的关系。我必须马上说,Person 模型有一个映射并且它有效。

但是如果我指定属性访问模式:

builder.HasMany(e => e.PersonLinks)
   .WithOne(e => e.Team)
   .HasForeignKey(e => e.TeamId)
   .Metadata.PrincipalToDependent.SetPropertyAccessMode(PropertyAccessMode.Field);

builder.HasMany(e => e.TeamLinks)
   .WithOne(e => e.Person)
   .HasForeignKey(e => e.PersonId)
   .Metadata.PrincipalToDependent.SetPropertyAccessMode(PropertyAccessMode.Field);
Run Code Online (Sandbox Code Playgroud)

如果我尝试获取dbContext.Teams.Include(t => t.PersonLinks).ThenInclude(t => t.Person),我会收到一个错误:“...PersonId1 列不存在...”,我有这个用于 TeamPerson 模型映射:

builder.Property(e => e.PersonId).IsRequired().HasColumnName("person_id");
Run Code Online (Sandbox Code Playgroud)

我的错误是什么,或者有什么其他方法可以在这里达到集合的封装?

c# postgresql domain-driven-design entity-framework ef-core-3.1

5
推荐指数
1
解决办法
632
查看次数