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

Fixes for return_on_mfa code #92

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

cyberjunky
Copy link
Contributor

@cyberjunky cyberjunky commented Jan 22, 2025

With these changes I got it working, some returns where missing, I could not get it working with returning one result variable.

Summary by CodeRabbit

  • New Features

    • Enhanced Multi-Factor Authentication (MFA) login handling
    • Improved token management during login process
  • Bug Fixes

    • Refined MFA login flow to provide clearer result handling
  • Documentation

    • Updated README with new login method usage
  • Chores

    • Version bumped to 0.5.3

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request introduces changes to the Multi-Factor Authentication (MFA) handling process in the Garth library. The modifications primarily affect the login mechanism across multiple files, including README.md, garth/http.py, and garth/sso.py. The changes update how login results are returned and processed, specifically when MFA is required. The version number has been incremented to 0.5.3 to reflect these modifications.

Changes

File Change Summary
README.md - Updated MFA login example to use two-result unpacking
- Modified garth.login() and garth.resume_login() method calls
garth/http.py - Updated login() method to return OAuth1 and OAuth2 tokens
- Added new resume_login() method with similar token handling
garth/sso.py - Modified MFA return value structure
- Now returns a tuple with "needs_mfa" string and client state dictionary
garth/version.py - Incremented version from 0.5.2 to 0.5.3

Sequence Diagram

sequenceDiagram
    participant User
    participant Garth
    participant SSO
    
    User->>Garth: login(email, password)
    Garth->>SSO: Attempt login
    alt MFA Required
        SSO-->>Garth: Return ("needs_mfa", client_state)
        Garth-->>User: Prompt for MFA code
        User->>Garth: Provide MFA code
        Garth->>SSO: Resume login with MFA
        SSO-->>Garth: Return OAuth1 and OAuth2 tokens
    else Login Successful
        SSO-->>Garth: Return OAuth1 and OAuth2 tokens
    end
    Garth-->>User: Complete login
Loading

Possibly related PRs

  • support return_on_mfa #84: The changes in this PR directly relate to the handling of Multi-Factor Authentication (MFA) in the login process, which aligns with the modifications made in the main PR regarding the garth.login() function and the introduction of the return_on_mfa parameter.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7de1671 and e97afb1.

📒 Files selected for processing (2)
  • garth/http.py (1 hunks)
  • garth/sso.py (3 hunks)
🧰 Additional context used
🪛 GitHub Actions: CI
garth/http.py

[warning] Code formatting issues detected. File needs to be reformatted using Ruff formatter.


[warning] Trailing whitespace found in file

🔇 Additional comments (4)
garth/http.py (1)

167-167: LGTM! Return statement aligns with updated MFA handling.

The explicit return of both tokens improves clarity and matches the updated return type in sso.py.

🧰 Tools
🪛 GitHub Actions: CI

[warning] Code formatting issues detected. File needs to be reformatted using Ruff formatter.


[warning] Trailing whitespace found in file

garth/sso.py (3)

4-4: LGTM! Good addition of Literal type.

The addition of Literal type import supports the improved type safety in the return type annotation.


77-77: LGTM! Return type annotation improves type safety.

The updated return type Tuple[OAuth1Token, OAuth2Token] | Tuple[Literal["needs_mfa"], dict] makes the MFA case more explicit and type-safe.


144-147: 🧹 Nitpick (assertive)

LGTM! Return structure matches the type annotation.

The tuple return "needs_mfa", {...} aligns with the updated return type and provides all necessary state for resume_login.

Consider adding a docstring update to clarify the return type change:

    Returns:
        If return_on_mfa=False (default):
            Tuple[OAuth1Token, OAuth2Token]: OAuth tokens after login
        If return_on_mfa=True and MFA required:
-            dict: Contains needs_mfa and client_state for resume_login()
+            Tuple[Literal["needs_mfa"], dict]: First element indicates MFA required,
+                second element contains state needed for resume_login()

Likely invalid or redundant comment.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 922f3c3 and 7de1671.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • garth/http.py (1 hunks)
  • garth/sso.py (1 hunks)
  • garth/version.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: CI
garth/http.py

[warning] Code formatting issues detected. File needs to be reformatted using Ruff formatter.


[warning] Trailing whitespace detected and needs to be removed.

🔇 Additional comments (3)
garth/http.py (1)

164-169: LGTM! The login method correctly handles the new return structure.

The changes properly unpack and store the OAuth tokens from the SSO login response.

🧰 Tools
🪛 GitHub Actions: CI

[warning] Code formatting issues detected. File needs to be reformatted using Ruff formatter.


[warning] Trailing whitespace detected and needs to be removed.

garth/version.py (1)

1-1: LGTM! Version bump is appropriate.

The increment to 0.5.3 aligns with semantic versioning for a backward-compatible bug fix.

README.md (1)

143-144: LGTM! Documentation accurately reflects the implementation changes.

The example code has been updated to demonstrate the new MFA handling flow, making it clearer and more explicit.

Also applies to: 146-146

garth/sso.py Show resolved Hide resolved
garth/http.py Outdated Show resolved Hide resolved
@cyberjunky
Copy link
Contributor Author

@matin Hi there, can you please have a quick look and merge if you have the time?
Otherwise I'm thinking it's maybe better to integrate parts of the code in Garmin Connect package.

@matin
Copy link
Owner

matin commented Jan 28, 2025

@cyberjunky I apologize I haven't had a change to review. I'm adding @felipao-mx as a maintainer to review and merge

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