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

feat: Apply config settings #170

Merged
merged 6 commits into from
Sep 11, 2024
Merged

Conversation

warcooft
Copy link
Contributor

@warcooft warcooft commented Sep 10, 2024

Because the login and registration routes are combined into one link, this makes it difficult to differentiate between OAuth login and OAuth registration. This can cause confusion.

for example: when a user intends to log in but instead gets registered, even though they don't want to register their email. Therefore, it needs to be prevented by using proper settings and its implementation must be placed inside the controller.

This PR allowed to override the oauth config from the settings.

Example:

// In the login controller, we don't need users to register their emails,
// so we need to configure the settings accordingly like this.
$oauthConfig = setting('ShieldOAuthConfig.oauthConfigs');
$oauthConfig['google']['allow_login'] = true;
$oauthConfig['google']['allow_register'] = false;

setting('ShieldOAuthConfig.oauthConfigs', $oauthConfig);

// and in the register controller, login or register are allowed and we 
// need to configure the settings accordingly like this.
$oauthConfig = setting('ShieldOAuthConfig.oauthConfigs');
$oauthConfig['google']['allow_login'] = true;
$oauthConfig['google']['allow_register'] = true;

setting('ShieldOAuthConfig.oauthConfigs', $oauthConfig);

Summary by CodeRabbit

  • New Features

    • Enhanced OAuth login and registration processes through improved configuration management.
    • Added support for a new settings management package to streamline configuration handling.
  • Bug Fixes

    • Resolved issues with user login and registration checks by updating configuration access methods.
  • Chores

    • Updated project dependencies to include codeigniter4/settings for better configuration management.
    • Improved metadata in the project configuration files.
    • Enhanced static analysis capabilities by including additional helper directories.

Copy link

coderabbitai bot commented Sep 10, 2024

Walkthrough

The changes in this pull request involve modifications to the OAuthController class, specifically replacing direct calls to the config() function with a new setting() function for accessing OAuth configuration values. This affects three methods: redirectOAuth, callBack, and syncingUserInfo. Additionally, the composer.json file has been updated to include a new dependency for codeigniter4/settings, along with enhancements to its metadata. The phpstan.neon.dist file has also been updated to improve static analysis capabilities.

Changes

File Change Summary
src/Controllers/OAuthController.php Replaced config() function calls with setting() function calls for accessing OAuth configurations in redirectOAuth, callBack, and syncingUserInfo methods.
composer.json Added new dependency "codeigniter4/settings": "^2.2" in the require section.
composer.json Added authors, homepage, minimum-stability, prefer-stable, require-dev, autoload, autoload-dev, scripts, config, and support sections.
phpstan.neon.dist Added - vendor/codeigniter4/settings/src/Helpers in scanDirectories for PHPStan configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant OAuthController
    participant ConfigManager

    User->>OAuthController: Request OAuth Login
    OAuthController->>ConfigManager: Call setting('ShieldOAuthConfig.oauthConfigs')
    ConfigManager-->>OAuthController: Return OAuth Config
    OAuthController->>User: Redirect to OAuth Provider
Loading
sequenceDiagram
    participant User
    participant OAuthController
    participant ConfigManager

    User->>OAuthController: OAuth Callback
    OAuthController->>ConfigManager: Call setting('ShieldOAuthConfig.registrationAllowed')
    ConfigManager-->>OAuthController: Return Registration Status
    alt Registration Allowed
        OAuthController->>User: Register User
    else Registration Not Allowed
        OAuthController->>User: Show Error
    end
Loading

🐇 "In the code where settings reside,
A new way to fetch, we now abide.
With setting() calls, the flow is clear,
OAuth's path is bright, no need to fear.
So hop along, let changes ring,
For better code, we joyfully sing!" 🎉


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a29f15f and 2af01d0.

Files selected for processing (1)
  • phpstan.neon.dist (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • phpstan.neon.dist

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2b1672e and 8f25ed3.

Files selected for processing (1)
  • src/Controllers/OAuthController.php (3 hunks)
Additional context used
GitHub Check: PHP 8.1 Static Analysis
src/Controllers/OAuthController.php

[failure] 35-35:
Function setting not found.


[failure] 96-96:
Function setting not found.


[failure] 167-167:
Function setting not found.

GitHub Check: PHP 8.0 Static Analysis
src/Controllers/OAuthController.php

[failure] 35-35:
Function setting not found.


[failure] 96-96:
Function setting not found.


[failure] 167-167:
Function setting not found.

GitHub Check: PHP 7.4 Static Analysis
src/Controllers/OAuthController.php

[failure] 35-35:
Function setting not found.


[failure] 96-96:
Function setting not found.


[failure] 167-167:
Function setting not found.

Additional comments not posted (3)
src/Controllers/OAuthController.php (3)

35-35: Approve the change, but verify the setting function.

The change aligns with the PR objective of enabling overriding OAuth configuration settings from the application settings.

However, static analysis tools report that the setting function is not found. Please ensure that the setting function is defined and works as expected.

Tools
GitHub Check: PHP 8.1 Static Analysis

[failure] 35-35:
Function setting not found.

GitHub Check: PHP 8.0 Static Analysis

[failure] 35-35:
Function setting not found.

GitHub Check: PHP 7.4 Static Analysis

[failure] 35-35:
Function setting not found.


96-96: Approve the change, but verify the setting function.

The change aligns with the PR objective of enabling overriding OAuth configuration settings from the application settings.

However, static analysis tools report that the setting function is not found. Please ensure that the setting function is defined and works as expected.

Tools
GitHub Check: PHP 8.1 Static Analysis

[failure] 96-96:
Function setting not found.

GitHub Check: PHP 8.0 Static Analysis

[failure] 96-96:
Function setting not found.

GitHub Check: PHP 7.4 Static Analysis

[failure] 96-96:
Function setting not found.


167-167: Approve the change, but verify the setting function.

The change aligns with the PR objective of enabling overriding OAuth configuration settings from the application settings.

However, static analysis tools report that the setting function is not found. Please ensure that the setting function is defined and works as expected.

Tools
GitHub Check: PHP 8.1 Static Analysis

[failure] 167-167:
Function setting not found.

GitHub Check: PHP 8.0 Static Analysis

[failure] 167-167:
Function setting not found.

GitHub Check: PHP 7.4 Static Analysis

[failure] 167-167:
Function setting not found.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8f25ed3 and 0fc0057.

Files selected for processing (1)
  • composer.json (1 hunks)
Additional comments not posted (1)
composer.json (1)

29-29: LGTM!

The addition of the codeigniter4/settings dependency with version constraint ^2.2 is approved. This change aligns with the PR objective of enabling the overriding of OAuth configuration settings directly from the application settings.

composer.json Outdated
@@ -25,7 +25,8 @@
"require": {
"php": "^7.4.3 || ^8.0 || ^8.1 || ^8.2",
"ext-curl": "*",
"codeigniter4/shield": "^1.0"
"codeigniter4/shield": "^1.0",
"codeigniter4/settings": "^2.2"
Copy link
Owner

Choose a reason for hiding this comment

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

I’d like to clarify that the Setting package is required for Shield to function properly, and in turn, Shield is essential for Shield OAuth. Therefore, it seems there’s no need for Setting package at this point, as the necessary dependencies are already in place.

Suggested change
"codeigniter4/settings": "^2.2"

@@ -32,7 +32,8 @@ public function redirectOAuth(string $oauthName): RedirectResponse
return redirect()->to(config('Auth')->loginRedirect());
}

if (config('ShieldOAuthConfig')->oauthConfigs[$oauthName]['allow_login'] === false) {
/** @phpstan-ignore-next-line */
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of using /** @phpstan-ignore-next-line */ to suppress the error, you can fix it by making the following change:

scanDirectories:
    - vendor/codeigniter4/settings/src/Helpers

This will allow PHPStan to properly scan the necessary directories and resolve the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your guidance. I have sent an update. please review it.

@datamweb datamweb added the enhancement New feature or request label Sep 11, 2024
@datamweb
Copy link
Owner

LGTM! Thanks!

@datamweb datamweb merged commit 4d31367 into datamweb:develop Sep 11, 2024
11 checks passed
@warcooft warcooft deleted the feat-setting branch September 11, 2024 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants