Skip to content

Conversation

@brettchaldecott
Copy link
Contributor

@brettchaldecott brettchaldecott commented Mar 14, 2025

Explain your changes

This fixes the token decoding logic in place for the user_details extraction.

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

Walkthrough

The pull request updates two methods in the KindeApiClient class within the kinde_sdk/kinde_api_client.py file. In is_authenticated_token, the method now returns True when the token is valid instead of None, and its annotated return type has been updated from dict to None. In _decode_token_if_needed_value, the redundant checks have been removed by directly retrieving the token via token_value.get(token_name). If the token exists, it is decoded using the signing key and returned as a dictionary; if not, a KindeTokenException is raised. Its signature has also changed from returning dict to None.

Changes

File Change Summary
kinde_sdk/kinde_api_client.py is_authenticated_token: Updated to return True for a valid token instead of None and modified the return type annotation from dict to None.

_decode_token_if_needed_value: Simplified by removing initial checks, now directly retrieves the token using token_value.get(token_name), decodes it with the signing key if present, or raises a KindeTokenException if absent; return type changed from dict to None.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant KindeApiClient

    Client->>KindeApiClient: is_authenticated_token(token_value)
    alt Token valid (not expired)
        KindeApiClient-->>Client: Returns True
    else Token expired
        KindeApiClient-->>Client: Returns default response
    end
Loading
sequenceDiagram
    participant Caller
    participant KindeApiClient

    Caller->>KindeApiClient: _decode_token_if_needed_value(token_name, token_value)
    KindeApiClient->>KindeApiClient: Retrieve token using token_value.get(token_name)
    alt Token exists
        KindeApiClient->>KindeApiClient: Decode token using signing key
        KindeApiClient-->>Caller: Returns decoded token dictionary
    else Token not found
        KindeApiClient-->>Caller: Raises KindeTokenException
    end
Loading

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be87772 and 77b4589.

📒 Files selected for processing (1)
  • kinde_sdk/kinde_api_client.py (2 hunks)
🔇 Additional comments (4)
kinde_sdk/kinde_api_client.py (4)

137-142: Return type inconsistency in is_authenticated_token method

The method signature indicates this method returns a dict but the implementation now returns True for authenticated tokens and None otherwise. This creates a type mismatch between the declared return type and the actual return values.

The method signature should be updated to reflect the actual return type:

-def is_authenticated_token(self, token_value: dict) -> dict:
+def is_authenticated_token(self, token_value: dict) -> Optional[bool]:

If the current behavior is required for backwards compatibility, at minimum add a docstring explaining the return type discrepancy to help future maintainers understand the design decision.


338-358: Improved token handling logic with cleaner implementation

The refactored code correctly simplifies the token handling by:

  1. Directly retrieving the token using get()
  2. Properly checking if it's a string type
  3. Only attempting to decode when necessary

This implementation is more robust and easier to maintain than the previous version.

However, there's a return type annotation inconsistency according to the AI summary. The method signature should be updated if it's intended to return None in some cases:

-def _decode_token_if_needed_value(self, token_name: str, token_value: dict) -> dict:
+def _decode_token_if_needed_value(self, token_name: str, token_value: dict) -> Dict[str, Any]:

341-342: Good type checking implementation

The isinstance() check is the correct way to verify if the token is a string type.


344-358: Proper error handling with clear failure path

The implementation now has a clear path for both success and failure cases:

  1. When signing key exists, decode and return the token
  2. When signing key doesn't exist, raise an appropriate exception with a descriptive message

This makes debugging and error handling more straightforward for clients of this API.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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: 1

🧹 Nitpick comments (1)
kinde_sdk/kinde_api_client.py (1)

338-356: Simplified token decoding logic

The token decoding logic has been improved by eliminating redundant checks and directly retrieving the token value. This is a cleaner implementation that maintains proper error handling.

There's an unnecessary semicolon at the end of line 354 that should be removed:

-            return {token_name: jwt.decode(**decode_token_params)};
+            return {token_name: jwt.decode(**decode_token_params)}

Also, the method signature indicates the return type is dict, which is correct for the implementation, but the AI summary indicates it was changed to return None. Please verify this is intentional:

-def _decode_token_if_needed_value(self, token_name: str, token_value: dict) -> dict:
+def _decode_token_if_needed_value(self, token_name: str, token_value: dict) -> None:

The actual implementation returns a dictionary, so the return type should remain dict.

🧰 Tools
🪛 Ruff (0.8.2)

354-354: Statement ends with an unnecessary semicolon

Remove unnecessary semicolon

(E703)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 143ebcb and 3e14511.

📒 Files selected for processing (1)
  • kinde_sdk/kinde_api_client.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
kinde_sdk/kinde_api_client.py

354-354: Statement ends with an unnecessary semicolon

Remove unnecessary semicolon

(E703)

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

🧹 Nitpick comments (1)
kinde_sdk/kinde_api_client.py (1)

357-357: Remove unnecessary semicolon

The statement ends with an unnecessary semicolon, which is not a Python convention.

-            return {token_name: jwt.decode(**decode_token_params)};
+            return {token_name: jwt.decode(**decode_token_params)}
🧰 Tools
🪛 Ruff (0.8.2)

357-357: Statement ends with an unnecessary semicolon

Remove unnecessary semicolon

(E703)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e14511 and 7c7c59a.

📒 Files selected for processing (1)
  • kinde_sdk/kinde_api_client.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
kinde_sdk/kinde_api_client.py

357-357: Statement ends with an unnecessary semicolon

Remove unnecessary semicolon

(E703)

🔇 Additional comments (2)
kinde_sdk/kinde_api_client.py (2)

137-142: Return type inconsistency in is_authenticated_token method

The method signature indicates this method returns a dict but the implementation now returns True for authenticated tokens and None otherwise. This creates a type mismatch between the declared return type and the actual return values.

The method signature should be updated to reflect the actual return type:

-def is_authenticated_token(self, token_value: dict) -> dict:
+def is_authenticated_token(self, token_value: dict) -> bool:

Also, consider updating the method to return False instead of None to maintain consistency with the boolean return type:

-    return None
+    return False

338-359: ⚠️ Potential issue

Return type inconsistency in _decode_token_if_needed_value method

The method signature indicates this method returns a dict but according to the AI summary, it has been changed to return None. However, the implementation actually returns a dictionary. Update the method signature to accurately reflect the return type.

-def _decode_token_if_needed_value(self, token_name: str, token_value: dict) -> dict:
+def _decode_token_if_needed_value(self, token_name: str, token_value: dict) -> dict:

Also, verify that all calling code expects a dictionary return value.

Likely an incorrect or invalid review comment.

🧰 Tools
🪛 Ruff (0.8.2)

357-357: Statement ends with an unnecessary semicolon

Remove unnecessary semicolon

(E703)

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c7c59a and be87772.

📒 Files selected for processing (1)
  • kinde_sdk/kinde_api_client.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
kinde_sdk/kinde_api_client.py

356-356: Statement ends with an unnecessary semicolon

Remove unnecessary semicolon

(E703)

🔇 Additional comments (3)
kinde_sdk/kinde_api_client.py (3)

137-142: Return type inconsistency in is_authenticated_token method

The method signature indicates this method returns a dict but the implementation now returns True for authenticated tokens and None otherwise. This creates a type mismatch between the declared return type and the actual return values.

The method signature should be updated to reflect the actual return type:

-def is_authenticated_token(self, token_value: dict) -> dict:
+def is_authenticated_token(self, token_value: dict) -> bool:

Also, consider updating the method to return False instead of None to maintain consistency with the boolean return type:

-    return None
+    return False

338-342: Improved error handling for token validation

The new implementation correctly simplifies token retrieval using get() and properly checks if the token is a string. This is a good improvement that makes the code more robust.


344-357: Well-structured JWT token decoding implementation

The restructured JWT decoding logic is now more straightforward and properly handles the case when a signing key exists. The code is now more maintainable and easier to follow.

🧰 Tools
🪛 Ruff (0.8.2)

356-356: Statement ends with an unnecessary semicolon

Remove unnecessary semicolon

(E703)

@KeeganBeuthin
Copy link
Contributor

Hello, I have had the chance to run tests on this, I can confirm everything is running soundly on my end. I haven't encountered any issues thus far

@brettchaldecott brettchaldecott merged commit 3ceae44 into kinde-oss:main Mar 14, 2025
6 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jun 6, 2025
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.

2 participants