-
Notifications
You must be signed in to change notification settings - Fork 5
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
[VATIS-106] Add support for IDS validation token #66
Conversation
WalkthroughThis pull request introduces a new client authentication mechanism for the vATIS application. The changes involve adding an Changes
Sequence DiagramsequenceDiagram
participant AtisBuilder
participant ClientAuth
participant JwtHelper
participant Downloader
AtisBuilder->>ClientAuth: Call IdsValidationKey()
ClientAuth-->>AtisBuilder: Return validation key
alt Validation key exists
AtisBuilder->>JwtHelper: GenerateJwt()
JwtHelper-->>AtisBuilder: Return JWT
AtisBuilder->>Downloader: PostJson with JWT
else No validation key
AtisBuilder->>Downloader: PostJson without JWT
end
Possibly related PRs
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 4
🧹 Nitpick comments (4)
Vatsim.Network/IClientAuth.cs (1)
5-5
: Add XML documentation for the new method.Please add XML documentation for the
IdsValidationKey
method to describe its purpose, return value, and when it might return null.+ /// <summary> + /// Gets the validation key used for IDS authentication. + /// </summary> + /// <returns>The validation key if available; otherwise, null.</returns> string? IdsValidationKey();vATIS.Desktop/Utils/JwtHelper.cs (2)
41-43
: Consider making token lifetime configurable.The token expiration time is hardcoded to 5 minutes. Consider making this configurable based on security requirements.
+ private static readonly TimeSpan _tokenLifetime = TimeSpan.FromMinutes(5); + NotBefore = DateTime.UtcNow, - Expires = DateTime.UtcNow.Add(TimeSpan.FromMinutes(5)), + Expires = DateTime.UtcNow.Add(_tokenLifetime),
36-45
: Add support for custom claims.The token generation is currently inflexible. Consider adding support for custom claims to make the utility more reusable.
- public static string GenerateJwt(string? privateKey, string keyId) + public static string GenerateJwt(string? privateKey, string keyId, IDictionary<string, object>? customClaims = null) { // ... existing validation code ... var handler = new JsonWebTokenHandler(); + var claims = new Dictionary<string, object>(); + if (customClaims != null) + { + foreach (var claim in customClaims) + { + claims.Add(claim.Key, claim.Value); + } + } return handler.CreateToken(new SecurityTokenDescriptor { Issuer = "vatis.app", Audience = "vatis.app", NotBefore = DateTime.UtcNow, Expires = DateTime.UtcNow.Add(TimeSpan.FromMinutes(5)), + Claims = claims, SigningCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.RsaSha256) });vATIS.Desktop/Atis/AtisBuilder.cs (1)
133-133
: Consider adding JWT to request headers instead of passing as parameter.For better security and adherence to JWT best practices, consider passing the JWT token in the Authorization header instead of as a parameter.
-await _downloader.PostJson(station.IdsEndpoint, jsonSerialized, jwt); +var headers = jwt != null ? new Dictionary<string, string> { { "Authorization", $"Bearer {jwt}" } } : null; +await _downloader.PostJson(station.IdsEndpoint, jsonSerialized, headers);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Vatsim.Network/ClientAuth.cs
(1 hunks)Vatsim.Network/IClientAuth.cs
(1 hunks)vATIS.Desktop/Atis/AtisBuilder.cs
(4 hunks)vATIS.Desktop/Utils/JwtHelper.cs
(1 hunks)vATIS.sln.DotSettings
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: build (macos-latest)
- GitHub Check: build (windows-latest)
- GitHub Check: Analyze (cpp)
- GitHub Check: build (ubuntu-latest)
- GitHub Check: Analyze (csharp)
🔇 Additional comments (3)
Vatsim.Network/ClientAuth.cs (1)
22-25
: Add XML documentation and implement the method.Two suggestions:
- Add XML documentation to match the interface.
- Implement the method instead of throwing NotImplementedException.
Would you like me to help with the implementation of this method? Please provide the requirements for the validation key generation.
vATIS.sln.DotSettings (1)
14-14
: LGTM!The addition of 'jwks' to the user dictionary is appropriate given the JWT implementation.
vATIS.Desktop/Atis/AtisBuilder.cs (1)
18-18
: LGTM! Clean dependency injection implementation.The implementation follows dependency injection best practices using interface-based injection.
Also applies to: 40-40, 49-51, 57-57
Summary by CodeRabbit
Release Notes
New Features
Improvements
Chores