Skip to content
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

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

justinshannon
Copy link
Contributor

@justinshannon justinshannon commented Jan 14, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for generating JWT tokens for IDS server validation
    • Introduced new client authentication method for enhanced security
  • Improvements

    • Updated ATIS builder to include client authentication
    • Added utility method for JWT token generation
  • Chores

    • Updated solution settings to include new terminology

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Walkthrough

This pull request introduces a new client authentication mechanism for the vATIS application. The changes involve adding an IdsValidationKey method to the ClientAuth and IClientAuth interfaces, creating a new JwtHelper utility for generating JSON Web Tokens (JWTs), and modifying the AtisBuilder to support optional JWT generation during IDS updates. The implementation provides a flexible approach to authentication with an optional validation key generation process.

Changes

File Change Summary
Vatsim.Network/IClientAuth.cs Added IdsValidationKey() method returning a nullable string
Vatsim.Network/ClientAuth.cs Implemented IdsValidationKey() method (currently throws NotImplementedException)
vATIS.Desktop/Atis/AtisBuilder.cs Added IClientAuth dependency and updated constructor
Modified UpdateIds method to optionally generate JWT
vATIS.Desktop/Utils/JwtHelper.cs New utility class for generating signed JWTs
vATIS.sln.DotSettings Added "jwks" to user dictionary

Sequence Diagram

sequenceDiagram
    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
Loading

Possibly related PRs

Poem

🐰 A rabbit's tale of tokens bright,
JWT dancing in the digital light,
Authentication's new embrace,
With keys that spin and tokens trace,
Security hops with playful might! 🔐


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c2eef1 and 3f3a1da.

📒 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:

  1. Add XML documentation to match the interface.
  2. 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

vATIS.Desktop/Utils/JwtHelper.cs Show resolved Hide resolved
vATIS.Desktop/Utils/JwtHelper.cs Show resolved Hide resolved
vATIS.Desktop/Utils/JwtHelper.cs Show resolved Hide resolved
vATIS.Desktop/Atis/AtisBuilder.cs Show resolved Hide resolved
@justinshannon justinshannon added this pull request to the merge queue Jan 15, 2025
Merged via the queue into main with commit 093ee81 Jan 15, 2025
7 checks passed
@justinshannon justinshannon deleted the ids-validation-token branch January 15, 2025 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant