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

Create speaker account with SSO as part of the answer to Call for Proposals #520

Merged
merged 9 commits into from
Jan 25, 2025

Conversation

HungNgien
Copy link
Contributor

@HungNgien HungNgien commented Jan 24, 2025

Make social login to redirect to previous page when Login with SSO in other components

Summary by Sourcery

New Features:

  • Added support for redirecting users back to the original page after logging in with SSO from other components.

Copy link

sourcery-ai bot commented Jan 24, 2025

Reviewer's Guide by Sourcery

This pull request introduces the functionality to redirect users back to the original page after they log in using SSO from other components. It also includes a new schema for OAuth2 parameters.

Sequence diagram for SSO login with redirect flow

sequenceDiagram
    actor User
    participant Frontend
    participant OAuthLoginView
    participant OAuthReturnView
    participant Provider
    participant User_DB

    User->>Frontend: Click Login with SSO
    Frontend->>OAuthLoginView: GET /oauth_login/{provider}/ with next URL
    OAuthLoginView->>OAuthLoginView: set_oauth2_params()
    Note over OAuthLoginView: Store OAuth2 params in session
    OAuthLoginView->>Provider: Redirect to provider login URL
    Provider->>OAuthReturnView: Return with auth data
    OAuthReturnView->>User_DB: get_or_create_user()
    OAuthReturnView->>OAuthReturnView: process_login_and_set_cookie()
    Note over OAuthReturnView: Retrieve OAuth2 params from session
    OAuthReturnView->>Frontend: Redirect to original page with OAuth2 params
Loading

Class diagram for OAuth views and parameters

classDiagram
    class OAuthLoginView {
        +get(request: HttpRequest, provider: str): HttpResponse
        -set_oauth2_params(request: HttpRequest): None
    }
    class OAuthReturnView {
        +get(request: HttpRequest): HttpResponse
        -get_or_create_user(request: HttpRequest): User
    }
    class OAuth2Params {
        +response_type: str
        +client_id: str
        +redirect_uri: str
        +scope: str
        +state: str
    }
    note for OAuth2Params "New model for OAuth2 parameters"
    OAuthLoginView ..> OAuth2Params : uses
    OAuthReturnView ..> OAuth2Params : uses
Loading

File-Level Changes

Change Details Files
Added support for redirecting users back to the original page after logging in with SSO.
  • Created a new OAuthLoginView class to handle the login process.
  • Added a set_oauth2_params method to store OAuth2 parameters in the session.
  • Modified OAuthReturnView to retrieve and use stored OAuth2 parameters for redirection.
  • Added logic to handle cases where the user does not have an email address.
src/pretix/plugins/socialauth/views.py
Created a new schema for OAuth2 parameters.
  • Created a OAuth2Params model using Pydantic to validate OAuth2 parameters.
src/pretix/plugins/socialauth/schemas/oauth2_params.py
Modified the login button to include the 'next' parameter.
  • Modified the login button to include the 'next' parameter to redirect the user after login.
src/pretix/control/templates/pretixcontrol/auth/login.html
Updated URLs to use the new view classes.
  • Updated the URLs to use the new OAuthLoginView and OAuthReturnView classes.
src/pretix/plugins/socialauth/urls.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@HungNgien HungNgien marked this pull request as ready for review January 24, 2025 10:05
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @HungNgien - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • The URL validation should be strengthened to prevent path traversal attacks (link)
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🔴 Security: 1 blocking issue, 1 other issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

parsed = urlparse(next_url)

# Only allow relative URLs
if parsed.netloc or parsed.scheme:
Copy link

Choose a reason for hiding this comment

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

🚨 issue (security): The URL validation should be strengthened to prevent path traversal attacks

Consider adding checks for '../' sequences and ensuring the path starts with an allowed prefix to prevent unauthorized access to different parts of the application.

messages.error(
request, _("Error while authorizing: no email address available.")
)
logger.error("Error while authorizing: %s", e)
Copy link

Choose a reason for hiding this comment

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

🚨 issue (security): Logging raw exception could expose sensitive information

Consider logging a sanitized error message instead of the raw exception to prevent potential exposure of sensitive information in logs.

@mariobehling mariobehling merged commit de08ff0 into fossasia:development Jan 25, 2025
3 of 5 checks passed
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.

3 participants