Wilson 7x (perf improvements in .NET 8) Discussion Forum ⚒️ #2092
Replies: 12 comments 38 replies
-
@leastprivilege @kevinchalet @brockallen @blowdart @davidfowl @eerhardt @Tratcher |
Beta Was this translation helpful? Give feedback.
-
Will ASP.NET Core 8's OIDC and JWT handlers switch, and if so then when (if they've not already)? |
Beta Was this translation helpful? Give feedback.
-
7.0.0-preview is now on NuGet if you want to try and provide feedback. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Please update this thread when that is known and/or released, please.
Not sure if I have an opinion. I just need to know to support our customers since I suspect they will come to us with questions/issues. |
Beta Was this translation helpful? Give feedback.
-
Out of curiosity, do you plan on aligning the versions only for the previews or forever? Since it's part of .NET, ASP.NET Core has a quite slow release pace (one major release a year, no intermediate minor version and a few patches to fix only the most critical bugs), so it would be sad to see IM releases slow down 😓 |
Beta Was this translation helpful? Give feedback.
-
EDIT: Sorry this appears to be an issue with Fixed in this commit tgstation/tgstation-server@651c810. Essentially, just updated to setting Updating to .NET Preview 8, specifically Setup: // configure bearer token validation
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(jwtBearerOptions =>
{
// this line isn't actually run until the first request is made
// at that point tokenFactory will be populated
jwtBearerOptions.TokenValidationParameters = tokenFactory.ValidationParameters;
jwtBearerOptions.Events = new JwtBearerEvents
{
// Application is our composition root so this monstrosity of a line is okay
// At least, that's what I tell myself to sleep at night
OnTokenValidated = ctx => ctx
.HttpContext
.RequestServices
.GetRequiredService<IClaimsInjector>()
.InjectClaimsIntoContext(
ctx,
ctx.HttpContext.RequestAborted),
};
});
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
ValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(signingKeyBytes),
ValidateIssuer = true,
ValidIssuer = assemblyInformationProvider.AssemblyName.Name,
ValidateLifetime = true,
ValidateAudience = true,
ValidAudience = typeof(TokenResponse).Assembly.GetName().Name,
ClockSkew = TimeSpan.FromMinutes(securityConfiguration.TokenClockSkewMinutes),
RequireSignedTokens = true,
RequireExpirationTime = true,
};
public async Task InjectClaimsIntoContext(TokenValidatedContext tokenValidatedContext, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(tokenValidatedContext);
// Find the user id in the token
var userIdClaim = tokenValidatedContext.Principal.FindFirst(JwtRegisteredClaimNames.Sub);
if (userIdClaim == default)
throw new InvalidOperationException("Missing required claim!"); // Hitting this error
long userId;
try
{
userId = Int64.Parse(userIdClaim.Value, CultureInfo.InvariantCulture);
}
catch (Exception e)
{
throw new InvalidOperationException("Failed to parse user ID!", e);
}
... |
Beta Was this translation helpful? Give feedback.
-
@kevinchalet @brockallen @leastprivilege We want to discuss the differences of serialization of a JsonWebToken in 7 project. Preview4 will support collections {list, collection, enumeration, dictionary} where the 'object' resolves to C# type {int, bool, string, datetime, JsonElement, different variations of numbers}. Dictionary<string,object>{"a",new List{"str1",new Dictionary<string,string>{{"key1","value1"}}}} Consider: class MyClass{} Preview4 recognizes JsonElement so if MyClass was serialized into a JsonElement that was added to the Dictionary, it would be serialized. We are very interested if the community sees this as a blocker for asp.net 8. Do you think we will need extensibility such as callbacks for unknown types in 7? |
Beta Was this translation helpful? Give feedback.
-
I personally don't mind having to directly use
Doesn't seem like a great idea to me: if a type is too complex to be serialized/not supported, an exception should be thrown instead of trying to use |
Beta Was this translation helpful? Give feedback.
-
Today, I updated my ASP.NET Core MVC web API project running with OIDC under .NET 7 to use the latest 7.0.2 version of the "System.IdentityModel.Tokens.Jwt" NuGet package. Now every web API request fails with this:
I don't have a direct dependency towards the mentioned "Microsoft.IdentityModel.Json.JsonConvert" package, rather it's just a transitive dependency of "System.IdentityModel.Tokens.Jwt", which you'd think should be unproblematic to resolve. Through debugging, I also get this variant:
I see that @Cyberboss has already mentioned earlier that there's a potential bearer access token validation issue with the "Microsoft.AspNetCore.Authentication.JwtBearer" NuGet package mentioned in the latter stack trace. I've debugged the access token validation configuration logic, but nothing bad happens there. The error occurs once the control is given over to ASP.NET Core. I've tested both of these options, suggested earlier:
and:
None of these changes make any difference whatsoever. More complete original code:
|
Beta Was this translation helpful? Give feedback.
-
@mgroetan it is important to have all the versions of IdentityModel to be the same version. |
Beta Was this translation helpful? Give feedback.
-
@mgroetan we have a work item to mark each nuget of IdentityModel to require an exact version of the other packages. |
Beta Was this translation helpful? Give feedback.
-
The team is hard at work to bring:
There will, however, be breaking changes between M.IdentityModel 6x and M.IdentityModel 7x, which are documented in a wiki coming soon.
You can follow the changes in the dev7x branch and we will be shipping previews packages to NuGet by end of month (June 2023).
Your feedback is much appreciated and needed so that we ensure we meet your needs and have a solid experience for you. Please leave comments, questions, feedback in the discussion thread and we will address them as quickly as possible.
Beta Was this translation helpful? Give feedback.
All reactions