-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to Microsoft.IdentityModel.JsonWebTokens package #7269
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Security.Claims; | ||
using Microsoft.IdentityModel.Tokens; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Nethermind.Tools.Kute.SecretProvider; | ||
using Nethermind.Tools.Kute.SystemClock; | ||
|
||
|
@@ -32,12 +31,12 @@ public JwtAuth(ISystemClock clock, ISecretProvider secretProvider) | |
|
||
private string GenerateAuthToken() | ||
{ | ||
var signingKey = new SymmetricSecurityKey(_secret); | ||
var credentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256); | ||
var claims = new[] { new Claim(JwtRegisteredClaimNames.Iat, _clock.UtcNow.ToUnixTimeSeconds().ToString(), ClaimValueTypes.Integer64) }; | ||
var token = new JwtSecurityToken(claims: claims, signingCredentials: credentials); | ||
var handler = new JwtSecurityTokenHandler(); | ||
var handler = new JsonWebTokenHandler { SetDefaultTimesOnTokenCreation = false }; | ||
|
||
return handler.WriteToken(token); | ||
return handler.CreateToken(new SecurityTokenDescriptor | ||
{ | ||
IssuedAt = _clock.UtcNow.UtcDateTime, | ||
SigningCredentials = new(new SymmetricSecurityKey(_secret), SecurityAlgorithms.HmacSha256) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we cache There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried not to make any other changes but replace the API as I don't know much about Kute. But the suggested change is small enough, so applied in the commit below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be no need for caching since we're already caching the JWT generation. By default, this code will be executed once per minute. |
||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might be reintroducing #6936. @stdevMac please check again with Reth or by following that PR discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's failing to compile:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emlautarom1 The updated code has been tested to ensure it generates the same token as it was with the replaced package.