Skip to content

fix: adhere to Lcobucci\JWT v5 interface#209

Merged
kilatib merged 1 commit into
oat-sa:masterfrom
kochen:use_unencryptedtoken_instead_of_plain_token
Aug 4, 2025
Merged

fix: adhere to Lcobucci\JWT v5 interface#209
kilatib merged 1 commit into
oat-sa:masterfrom
kochen:use_unencryptedtoken_instead_of_plain_token

Conversation

@kochen

@kochen kochen commented Jul 27, 2025

Copy link
Copy Markdown
Contributor

closes #208

Summary by CodeRabbit

  • Refactor
    • Updated internal handling of security tokens to improve maintainability. No changes to user-facing features or behavior.

@coderabbitai

coderabbitai Bot commented Jul 27, 2025

Copy link
Copy Markdown

Walkthrough

The Token class in src/Security/Jwt/Token.php has been refactored to depend on Lcobucci\JWT\UnencryptedToken instead of Lcobucci\JWT\Token\Plain. The constructor and all internal references have been updated accordingly, with no changes to the logic of public methods.

Changes

File(s) Change Summary
src/Security/Jwt/Token.php Refactored to use UnencryptedToken instead of Token\Plain; updated constructor and methods

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related issues

Suggested reviewers

  • kilatib

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/Security/Jwt/Token.php (2)

35-41: Rename local variable for clarity.

Using $headers to store a generic Collection obscures intent and is misleading in getHeaders(). Renaming makes the purpose explicit and avoids confusion, especially when mirrored in getClaims().

-        $headers = new Collection();
-
-        return $headers->add($this->token->headers()->all());
+        $collection = new Collection();
+
+        return $collection->add($this->token->headers()->all());

42-47: Duplicate logic between getHeaders() and getClaims().

Both methods instantiate a Collection, call add(), then return it. Consider extracting this into a private helper to reduce duplication and future-proof changes to collection creation.

private function buildCollection(array $items): CollectionInterface
{
    return (new Collection())->add($items);
}

Then:

-        $headers = new Collection();
-        return $headers->add($this->token->claims()->all());
+        return $this->buildCollection($this->token->claims()->all());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 899aea6 and 3cbb736.

📒 Files selected for processing (1)
  • src/Security/Jwt/Token.php (1 hunks)
🔇 Additional comments (3)
src/Security/Jwt/Token.php (3)

25-25: Confirm composer dependency bump to v5.0 of lcobucci/jwt.

The switch to Lcobucci\JWT\UnencryptedToken requires the 5.x release line. Please verify that composer.json has been updated accordingly and that no other parts of the codebase still reference Lcobucci\JWT\Token\Plain.


31-33: Constructor change looks correct.

The promoted property cleanly replaces the previous field; visibility and type are appropriate.


51-52: No issues with toString() adaptation.

The method simply delegates to the new token instance; behaviour is preserved.

@kochen

kochen commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

@wazelin @kilatib would you be able to take a look at this?

@kilatib kilatib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kochen Thank you for the PR — it looks great and aligns well with v5! 🙌
However, it currently breaks compatibility with v4.

Would you be open to extending support for both versions? There are a few possible approaches:

  1. Class detection in constructor
    We could detect the token class here and allow both types.
    This would require creating the Lcobucci\JWT\Token\Plain namespace manually if it doesn't exist.

  2. Separate token classes
    Create TokenV4 and TokenV5 classes that extend the base token.
    Not ideal, but it would allow us to modify the logic here accordingly.

  3. Symfony DI with factory
    Use Symfony's dependency injection to provide the correct token class via a factory.
    This is cleaner but requires a bit more setup.

Let me know what you think — happy to help with implementation if needed!

private $plainToken;

public function __construct(Plain $plainToken)
public function __construct(private UnencryptedToken $token)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function __construct(private UnencryptedToken $token)
public function __construct(private UnencryptedToken|PlainToken $token)

namespace OAT\Library\Lti1p3Core\Security\Jwt;

use Lcobucci\JWT\Token\Plain;
use Lcobucci\JWT\UnencryptedToken;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Lcobucci\JWT\UnencryptedToken
use Lcobucci\JWT\Token\Plain

@kochen

kochen commented Jul 29, 2025

Copy link
Copy Markdown
Contributor Author

@kochen Thank you for the PR — it looks great and aligns well with v5! 🙌 However, it currently breaks compatibility with v4.

Would you be open to extending support for both versions? There are a few possible approaches:

  1. Class detection in constructor
    We could detect the token class here and allow both types.
    This would require creating the Lcobucci\JWT\Token\Plain namespace manually if it doesn't exist.
  2. Separate token classes
    Create TokenV4 and TokenV5 classes that extend the base token.
    Not ideal, but it would allow us to modify the logic here accordingly.
  3. Symfony DI with factory
    Use Symfony's dependency injection to provide the correct token class via a factory.
    This is cleaner but requires a bit more setup.

Let me know what you think — happy to help with implementation if needed!

Thanks @kilatib.
The suggested change, uses an interface which Plain implements anyway, so when $builder->getToken returns a Plain implements UnencryptedToken, we are not breaking anything...

            return new Token($builder->getToken($config->signer(), $config->signingKey()));

I have our own setup and implementation working perfectly fine with the suggested code change and lcobucci/jwt v4 (4.3.0 to be exact)

@kilatib

kilatib commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

@kochen Thank you for your response. We will need some time to complete our internal testing and will get back to you as soon as possible.

@kochen

kochen commented Jul 30, 2025

Copy link
Copy Markdown
Contributor Author

@kochen Thank you for your response. We will need some time to complete our internal testing and will get back to you as soon as possible.

thanks @kilatib.
please keep me updated - I could adjust if still needed...

@progys progys self-requested a review August 4, 2025 08:43

@kilatib kilatib left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual validation of the changes has been successfully completed with versions lcobucci/jwt 4.3 and 5.5. Everything is working perfectly — thank you for the PR!

  • New code is covered by tests (if applicable)
  • Tests are running successfully (old and new ones) on my local machine (if applicable)
  • New code is respecting code style rules
  • New code is respecting best practices
  • New code is not subject to concurrency issues (if applicable)
  • Feature is working correctly on my local machine (if applicable)
  • Acceptance criteria are respected
  • Pull request title and description are meaningful
  • Pull request's target is not master
  • Commits are following conventional commits
  • Changelog is updated according to changes (if applicable)
  • Documentation is updated according to changes (if applicable)

@kilatib kilatib merged commit 386de55 into oat-sa:master Aug 4, 2025
6 checks passed
kilatib added a commit to oat-sa/devkit-lti1p3 that referenced this pull request Aug 4, 2025
* chore: validate PR oat-sa/lib-lti1p3-core#209

* chore: update lcobucci/jwt to version 5.5

* chore: update oat-sa/lib-lti1p3-core to stable 7.2.5 version with suppot lcobucci/jwt ^5

* chore: apply support lcobucci/jwt ^5
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.

Security\Jwt\Token::__construct expects Lcobucci\JWT\Token\Plain, but parent type Lcobucci\JWT\UnencryptedToken provided

3 participants