Skip to content

Commit

Permalink
Merge pull request #108 from datamweb/load-config-from-other-namespace
Browse files Browse the repository at this point in the history
feat: use config file in the custom namespace
  • Loading branch information
datamweb committed Apr 11, 2024
2 parents 56682d0 + e2b587c commit 9b06b02
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
17 changes: 10 additions & 7 deletions docs/add_other_oauth.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,31 @@ declare(strict_types=1);

namespace App\Libraries\ShieldOAuth;

use CodeIgniter\HTTP\CURLRequest;
use Config\Services;
use Datamweb\ShieldOAuth\Config\ShieldOAuthConfig;
use Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth;
use Exception;

class YahooOAuth extends AbstractOAuth
{
// https://developer.yahoo.com/oauth2/guide/flows_authcode/#refresh-token-label
static private $API_CODE_URL = 'https://api.login.yahoo.com/oauth2/request_auth';
static private $API_TOKEN_URL = 'https://api.login.yahoo.com/oauth2/get_token';
static private $API_USER_INFO_URL = 'https://api.login.yahoo.com/openid/v1/userinfo';
static private $APPLICATION_NAME = 'ShieldOAuth';
private static string $API_CODE_URL = 'https://api.login.yahoo.com/oauth2/request_auth';
private static string $API_TOKEN_URL = 'https://api.login.yahoo.com/oauth2/get_token';
private static string $API_USER_INFO_URL = 'https://api.login.yahoo.com/openid/v1/userinfo';
private static string $APPLICATION_NAME = 'ShieldOAuth';

protected string $token;
protected $client;
protected $config;
protected CURLRequest $client;
protected ShieldOAuthConfig $config;
protected string $client_id;
protected string $client_secret;
protected string $callback_url;

public function __construct(string $token = '')
{
$this->token = $token;
$this->client = \Config\Services::curlrequest();
$this->client = Services::curlrequest();

$this->config = config('ShieldOAuthConfig');
$this->callback_url = base_url('oauth/' . $this->config->call_back_route);
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Migrations/2022-10-20-182737_ShieldOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
parent::__construct();

/** @var ShieldOAuthConfig $config */
$config = config(ShieldOAuthConfig::class);
$config = config('ShieldOAuthConfig');
$this->first_name = $config->usersColumnsName['first_name'];
$this->last_name = $config->usersColumnsName['last_name'];
$this->avatar = $config->usersColumnsName['avatar'];
Expand Down
3 changes: 2 additions & 1 deletion src/Libraries/GithubOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\HTTP\CURLRequest;
use Config\Services;
use Datamweb\ShieldOAuth\Config\ShieldOAuthConfig;
use Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth;
use Exception;

Expand All @@ -26,7 +27,7 @@ class GithubOAuth extends AbstractOAuth
private static string $APPLICATION_NAME = 'ShieldOAuth';
protected string $token;
protected CURLRequest $client;
protected ?object $config = null;
protected ShieldOAuthConfig $config;
protected string $client_id;
protected string $client_secret;
protected string $callback_url;
Expand Down
3 changes: 2 additions & 1 deletion src/Libraries/GoogleOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\HTTP\CURLRequest;
use Config\Services;
use Datamweb\ShieldOAuth\Config\ShieldOAuthConfig;
use Datamweb\ShieldOAuth\Libraries\Basic\AbstractOAuth;
use Exception;

Expand All @@ -26,7 +27,7 @@ class GoogleOAuth extends AbstractOAuth
private static string $APPLICATION_NAME = 'ShieldOAuth';
protected string $token;
protected CURLRequest $client;
protected ?object $config = null;
protected ShieldOAuthConfig $config;
protected string $client_id;
protected string $client_secret;
protected string $callback_url;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ShieldOAuthModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function initialize(): void
parent::initialize();

/** @var ShieldOAuthConfig $config */
$config = config(ShieldOAuthConfig::class);
$config = config('ShieldOAuthConfig');

// Merge properties with parent
$this->allowedFields = array_merge($this->allowedFields, [
Expand Down

0 comments on commit 9b06b02

Please sign in to comment.