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: use config file in the custom namespace #108

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

datamweb
Copy link
Owner

@datamweb datamweb commented Apr 11, 2024

See #104
This PR helps config file to be considered in the custom namespace.
For example :

Add app/Config/Autoload.php

    public $psr4 = [
        // ...
        'MyShieldOauth' => APPPATH . 'ThirdParty\ShieldOauth'
    ];

Add app\ThirdParty\ShieldOauth\Config\ShieldOAuthConfig.php :

<?php

declare(strict_types=1);

/**
 * This file is part of Shield OAuth.
 *
 * (c) Datamweb <pooya_parsa_dadashi@yahoo.com>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace MyShieldOauth\Config;

use Datamweb\ShieldOAuth\Config\ShieldOAuthConfig as OAuthConfig;

class ShieldOAuthConfig extends OAuthConfig
{
    /**
     * --------------------------------------------------------------------------
     * OAuth Configs
     * --------------------------------------------------------------------------
     *
     * Set keys and active any OAuth
     *
     * Here you can set the keys received from any OAuth servers.
     * for more information on getting keys:
     *
     * @see https://github.com/datamweb/shield-oauth/blob/develop/docs/get_keys.md
     *
     * @var array<string, array<string, bool|string>>
     */
    public array $oauthConfigs = [
        'github' => [
            'client_id'     => 'Get it from GitHub',
            'client_secret' => 'Get it from GitHub',

            'allow_login' => true,
        ],
        'google' => [
            'client_id'     => 'Get it from Google',
            'client_secret' => 'Get it from Google',

            'allow_login' => true,
        ],
        // 'yahoo' => [
        //     'client_id'     => 'Get it from Yahoo',
        //     'client_secret' => 'Get it from Yahoo',

        //     'allow_login' => true,
        // ],
    ];

    /**
     * --------------------------------------------------------------------------
     * Users Columns Name
     * --------------------------------------------------------------------------
     * If you use different names for the columns in the users table, use the following settings.
     *
     * Data of Table "users":
     * +----+----------+--------+...+------------+-----------+--------+
     * | id | username | status |...| first_name | last_name | avatar |
     * +----+----------+--------+...+------------+-----------+--------+
     * In fact, you set in which column the information received from the OAuth services should be recorded.
     * For example, the first name received from OAuth should be recorded in column 'first_name' of the 'users' table shield.
     * NOTE :
     *       This is suitable for those who have already installed the shield and created their own columns.
     *       In this case, there is no need to execute `php spark migrate -n Datamweb\ShieldOAuth`.
     *       Just set the following values with your table columns.
     *
     * @var array<string, string>
     */
    public array $usersColumnsName = [
        'first_name' => 'first_name',
        'last_name'  => 'last_name',
        'avatar'     => 'avatar',
    ];

    /**
     * --------------------------------------------------------------------------
     * Syncing User Info
     * --------------------------------------------------------------------------
     * Turn ON/OFF user data update
     *
     * If the user is already registered, by default when trying to login, their
     * information will be synchronized. If you want to cancel it, set to false.
     */
    public bool $syncingUserInfo = true;

    /**
     * --------------------------------------------------------------------------
     * Call Back Route
     * --------------------------------------------------------------------------
     * Set your custom call-back name
     *
     * When the user login with his profile, the OAuth server directs him to the following path.
     * So change this value only when you need to customize it.
     * By default, it returns to the following path:
     *      http://localhost:8080/oauth/call-back
     */
    public string $call_back_route = 'call-back';
}

These items are important to work properly.

  1. The ShieldOAuthConfig.php file should not be available app\Config\ShieldOAuthConfig.php.(If there is, delete it.)
  2. If you are using version CI4.5.0, this process will not work properly, due to a bug (See #fix: [FileLocator] Cannot declare class XXX, because the name is already in use codeigniter4/CodeIgniter4#8745).

@datamweb datamweb added the enhancement New feature or request label Apr 11, 2024
@datamweb datamweb merged commit 9b06b02 into develop Apr 11, 2024
10 checks passed
@datamweb datamweb deleted the load-config-from-other-namespace branch April 11, 2024 14:15
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.

1 participant