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 #508

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

HungNgien
Copy link
Collaborator

@HungNgien HungNgien commented Jan 15, 2025

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

Summary by Sourcery

New Features:

  • Added support for Single Sign-On (SSO) for speaker accounts during the Call for Proposals process.

Copy link

sourcery-ai bot commented Jan 15, 2025

Reviewer's Guide by Sourcery

This pull request implements Single Sign-On (SSO) for speaker accounts, allowing users to log in via external providers and redirecting them to the correct page after authentication. It also refactors the login views to use class-based views.

Sequence diagram for SSO login flow with redirect

sequenceDiagram
    actor User
    participant Browser
    participant OAuthLoginView
    participant OAuthReturnView
    participant ExternalProvider
    participant Database

    User->>Browser: Click 'Login with SSO'
    Browser->>OAuthLoginView: GET /oauth_login/{provider}/ with next URL
    OAuthLoginView->>OAuthLoginView: set_oauth2_params()
    OAuthLoginView->>ExternalProvider: Redirect to provider login
    ExternalProvider->>OAuthReturnView: Return with auth data
    OAuthReturnView->>Database: get_or_create_user()
    OAuthReturnView->>OAuthReturnView: prepare_oauth2_params()
    OAuthReturnView->>Browser: Redirect to original page
    Browser->>User: Show authenticated page
Loading

Class diagram for updated OAuth views

classDiagram
    class View {
        <<Django>>
    }
    class OAuthLoginView {
        +get(request, provider)
        -set_oauth2_params(request)
    }
    class OAuthReturnView {
        +get(request)
        -get_or_create_user(request)
        -prepare_oauth2_params(oauth2_params)
    }
    View <|-- OAuthLoginView
    View <|-- OAuthReturnView
    note for OAuthLoginView "Handles initial SSO request"
    note for OAuthReturnView "Processes SSO callback"
Loading

File-Level Changes

Change Details Files
Refactored login views to use class-based views.
  • Converted the function-based views oauth_login and oauth_return to class-based views OAuthLoginView and OAuthReturnView, respectively.
  • Added a method set_oauth2_params to OAuthLoginView to handle the 'next' parameter for redirection after login.
  • Added a method get_or_create_user to OAuthReturnView to retrieve or create the user based on their email address.
  • Added a method prepare_oauth2_params to OAuthReturnView to prepare parameters for the OAuth2 authorization view redirection.
  • Updated the URL patterns in urls.py to use the new class-based views.
src/pretix/plugins/socialauth/views.py
Implemented redirection to the previous page after SSO login.
  • Added logic to store the 'next' parameter in the session during the login process.
  • Added logic to retrieve the 'next' parameter from the session and redirect the user after successful SSO login.
  • Modified the login template to include the 'next' parameter in the SSO login link.
  • Added handling for OAuth2 parameters in the OAuthReturnView to facilitate redirection after authorization.
src/pretix/plugins/socialauth/views.py
src/pretix/control/templates/pretixcontrol/auth/login.html
Updated the login template to include the 'next' parameter in the SSO login link.
  • Added {% append_next request.GET.next %} to the SSO login link to include the 'next' parameter in the URL.
src/pretix/control/templates/pretixcontrol/auth/login.html

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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 15, 2025 04:44
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 - here's some feedback:

Overall Comments:

  • Consider cleaning up the oauth2_params session data in error cases as well to avoid stale data. This could be done by moving the cleanup to a finally block or similar.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 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.

src/pretix/plugins/socialauth/views.py Outdated Show resolved Hide resolved
@HungNgien HungNgien marked this pull request as draft January 15, 2025 07:43
@HungNgien HungNgien marked this pull request as ready for review January 15, 2025 08:22
@mariobehling mariobehling requested a review from hongquan January 16, 2025 04:19
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