Skip to content

Conversation

@Boy132
Copy link
Member

@Boy132 Boy132 commented Aug 4, 2025

Adds a new option to all providers to automatically create (& link) missing users. This is turned off by default.
These users will still recieve a "Account created" mail with a password reset link, if they wish to also setup a panel password.

grafik

@Boy132 Boy132 self-assigned this Aug 4, 2025
@avaruus1
Copy link

avaruus1 commented Aug 4, 2025

Maybe the option could just be called "Perform automated provisioning" or something similar? The current name seems kind of oververbose.

@jeffpeng3
Copy link

jeffpeng3 commented Aug 5, 2025

Maybe the option could just be called "Perform automated provisioning" or something similar? The current name seems kind of oververbose.

Maybe it could be named “Allow user creation”?

@rmartinoscar rmartinoscar removed their request for review August 7, 2025 08:29
@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

A new configuration option for OAuth was introduced to control whether missing users should be created automatically during OAuth authentication. This involved interface and method additions, logic updates in the OAuth controller, UI and translation updates, and refactoring of username generation logic to centralize it within the user creation service.

Changes

Cohort / File(s) Change Summary
OAuth Interface & Schema
app/Extensions/OAuth/OAuthSchemaInterface.php, app/Extensions/OAuth/Schemas/OAuthSchema.php
Added a shouldCreateMissingUsers() method to the interface and its implementation. Updated the schema form to include a toggle for this setting, with default and UI properties sourced from environment variables.
OAuth Authentication Logic
app/Http/Controllers/Auth/OAuthController.php
Refactored OAuth callback logic to use the new setting: checks for driver enablement and auto-creation permission, creates users if allowed using injected UserCreationService, and updates error handling and flow control.
User Creation Logic
app/Services/Subusers/SubuserCreationService.php, app/Services/Users/UserCreationService.php
Removed username generation from subuser creation service. Centralized username generation and sanitization in user creation service if username is missing or empty.
Localization
lang/en/admin/setting.php
Added a new language string key for the OAuth auto-create missing users toggle.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OAuthProvider
    participant OAuthController
    participant OAuthSchema
    participant UserCreationService

    User->>OAuthProvider: Initiate OAuth login
    OAuthProvider->>OAuthController: Redirect with callback data
    OAuthController->>OAuthSchema: shouldCreateMissingUsers()
    OAuthController->>OAuthController: Find user by OAuth ID
    alt User exists
        OAuthController->>User: Log in user
    else User does not exist
        alt Auto-create enabled
            OAuthController->>UserCreationService: Create user (with generated username if needed)
            UserCreationService-->>OAuthController: User created
            OAuthController->>User: Log in user
        else Auto-create disabled
            OAuthController->>User: Redirect to login with notification
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

In the warren of code, a toggle appears,
For OAuth bunnies with login fears.
Now missing users can hop right in,
If the setting says, "Let the fun begin!"
Usernames are crafted with care and delight—
A patch for the warren, both clever and right.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 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 7ceee67 and b313a29.

📒 Files selected for processing (1)
  • app/Http/Controllers/Auth/OAuthController.php (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/Http/Controllers/Auth/OAuthController.php
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch boy132/auto-create-oauth-user

🪧 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.
  • 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.

Support

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

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.

@Boy132 Boy132 requested a review from rmartinoscar August 7, 2025 08:50
Copy link

@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: 0

♻️ Duplicate comments (1)
app/Extensions/OAuth/OAuthSchemaInterface.php (1)

36-36: Method naming consideration.

While a previous reviewer suggested using singular form shouldCreateMissingUser(), the plural form shouldCreateMissingUsers() is actually more appropriate as this setting controls whether the system should create users (in general) when they're missing, not just a single user.

🧹 Nitpick comments (2)
lang/en/admin/setting.php (1)

100-100: Consider using a more concise label based on PR feedback.

The PR comments suggest alternative names like "Allow user creation" which is more concise and directly descriptive of the functionality.

-        'create_missing_users' => 'Auto Create Missing Users?',
+        'create_missing_users' => 'Allow user creation',
app/Http/Controllers/Auth/OAuthController.php (1)

82-86: Consider providing more specific error messages.

Both error scenarios show "No linked User found" but they represent different situations:

  1. Auto-creation is disabled
  2. Email is missing from OAuth provider
             // No user found and auto creation is disabled - redirect to normal login
             if (!$driver->shouldCreateMissingUsers()) {
                 Notification::make()
-                    ->title('No linked User found')
+                    ->title('No account found')
+                    ->body('Please create an account first or contact an administrator.')
                     ->danger()
                     ->persistent()
                     ->send();

                 return redirect()->route('auth.login');
             }

             $username = $oauthUser->getNickname();
             $email = $oauthUser->getEmail();

             // Incomplete data, can't create user - redirect to normal login
             if (!$email) {
                 Notification::make()
-                    ->title('No linked User found')
+                    ->title('Unable to create account')
+                    ->body('Email address is required but was not provided by the OAuth provider.')
                     ->danger()
                     ->persistent()
                     ->send();

Also applies to: 96-100

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 02e3e43 and 7ceee67.

📒 Files selected for processing (6)
  • app/Extensions/OAuth/OAuthSchemaInterface.php (1 hunks)
  • app/Extensions/OAuth/Schemas/OAuthSchema.php (3 hunks)
  • app/Http/Controllers/Auth/OAuthController.php (4 hunks)
  • app/Services/Subusers/SubuserCreationService.php (0 hunks)
  • app/Services/Users/UserCreationService.php (2 hunks)
  • lang/en/admin/setting.php (1 hunks)
💤 Files with no reviewable changes (1)
  • app/Services/Subusers/SubuserCreationService.php
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/Extensions/OAuth/OAuthSchemaInterface.php (1)
app/Extensions/OAuth/Schemas/OAuthSchema.php (1)
  • shouldCreateMissingUsers (113-118)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: MariaDB (8.4, mariadb:11.4)
  • GitHub Check: MariaDB (8.3, mariadb:11.4)
  • GitHub Check: MariaDB (8.4, mariadb:10.11)
  • GitHub Check: MariaDB (8.4, mariadb:10.6)
  • GitHub Check: MariaDB (8.3, mariadb:10.11)
  • GitHub Check: MariaDB (8.2, mariadb:11.4)
  • GitHub Check: MariaDB (8.2, mariadb:10.11)
  • GitHub Check: PostgreSQL (8.3, postgres:14)
  • GitHub Check: MariaDB (8.3, mariadb:10.6)
  • GitHub Check: MariaDB (8.2, mariadb:10.6)
  • GitHub Check: PostgreSQL (8.4, postgres:14)
  • GitHub Check: PostgreSQL (8.2, postgres:14)
  • GitHub Check: MySQL (8.4, mysql:8)
  • GitHub Check: MySQL (8.2, mysql:8)
  • GitHub Check: MySQL (8.3, mysql:8)
  • GitHub Check: SQLite (8.3)
  • GitHub Check: SQLite (8.4)
  • GitHub Check: SQLite (8.2)
🔇 Additional comments (4)
app/Services/Users/UserCreationService.php (2)

46-54: Good implementation of username generation and sanitization.

The code correctly generates a username from email when missing and applies sanitization to all usernames (both provided and generated), addressing previous review feedback.


50-54: SFTP compatibility confirmed with sanitized usernames

All SFTP entry points consistently use the stored $user->username (property that’s already stripped of dots and hyphens) when building the login string:

• tests/Integration/Api/Remote/SftpAuthenticationControllerTest.php’s getUsername()
• Remote\SftpAuthenticationController parses and validates the same sanitized username
• Filament Server Settings URL/username fields use auth()->user()->username

No further action is required—removing “.” and “-” during user creation does not break SFTP authentication.

app/Extensions/OAuth/Schemas/OAuthSchema.php (1)

58-68: Well-implemented OAuth configuration toggle and method.

The Toggle field configuration is comprehensive with proper state handling, UI customization, and the shouldCreateMissingUsers() method follows the established pattern used by isEnabled().

Also applies to: 113-118

app/Http/Controllers/Auth/OAuthController.php (1)

44-49: Excellent refactoring of OAuth callback logic.

The code properly delegates username generation to UserCreationService (addressing previous feedback), handles missing email validation, and cleanly separates the logic for existing vs new users.

Also applies to: 65-114

Copy link
Member

@rmartinoscar rmartinoscar left a comment

Choose a reason for hiding this comment

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

Im unable to checkout atm but code looks good

@Boy132 Boy132 merged commit 7c315ac into main Aug 7, 2025
26 checks passed
@Boy132 Boy132 deleted the boy132/auto-create-oauth-user branch August 7, 2025 09:22
@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants