Skip to content

Commit

Permalink
🚿 clean-up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed May 14, 2024
1 parent 240e5f8 commit 647a43d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .config/.env_example
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ FOURSQUARE_SECRET=
FOURSQUARE_CALLBACK_URL=
#FOURSQUARE_TESTUSER=

# https://github.com/settings/applications/
# https://github.com/settings/developers
GITHUB_KEY=
GITHUB_SECRET=
GITHUB_CALLBACK_URL=
Expand Down
9 changes: 4 additions & 5 deletions examples/OAuthExampleProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

/**
*
Expand All @@ -46,9 +45,9 @@ class OAuthExampleProviderFactory{

public function __construct(
protected OAuthProviderFactory $factory,
protected string $cfgDir = __DIR__.'/../.config',
string $envFile = '.env',
string $logLevel = LogLevel::INFO,
protected string $cfgDir,
string $envFile,
string $logLevel,
){
ini_set('date.timezone', 'UTC');

Expand Down Expand Up @@ -77,7 +76,7 @@ protected function initLogger(string|null $logLevel):LoggerInterface{
protected function initFileStorage():OAuthStorageInterface{
$options = new OAuthOptions;

$options->fileStoragePath = $this->cfgDir.'/.filestorage';
$options->fileStoragePath = rtrim($this->cfgDir, '/\\').'/.filestorage';

return new FileStorage('oauth-example', $options, $this->logger);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/get-token/_flow-oauth1.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
}
// step 1 (optional): display a login link
else{
echo '<a href="?login='.$name.'">connect with '.$name.'!</a>';
echo '<a href="?login='.$name.'">Connect with '.$name.'!</a>';
}
2 changes: 1 addition & 1 deletion examples/get-token/_flow-oauth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@
}
// step 1 (optional): display a login link
else{
echo '<a href="?login='.$name.'">connect with '.$name.'!</a>';
echo '<a href="?login='.$name.'">Connect with '.$name.'!</a>';
}
26 changes: 17 additions & 9 deletions examples/provider-example-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

use chillerlan\OAuth\Core\OAuthInterface;
use chillerlan\OAuth\OAuthProviderFactory;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use Psr\Log\LogLevel;

/**
* allow to use a different autoloader to make it easier to use the examples (@todo: WIP)
* allow to use a different autoloader to ease using the examples
*
* @var string $AUTOLOADER - path to an alternate autoloader
*/
Expand All @@ -23,26 +22,35 @@
/**
* these vars are supposed to be set before this file is included to ease testing
*
* @var string $CFGDIR - the directory where configuration is stored (.env, cacert, tokens)
* @var string $CFGDIR - the directory where configuration is stored (.env, cacert, tokens)
* @var string $ENVFILE - the name of the .env file in case it differs from the default
* @var string $LOGLEVEL - log level for the test logger, use 'none' to suppress logging
* @var array|null $PARAMS - additional params to pass to getAuthorizationURL()
* @var array|null $SCOPES - a set of scopes for the current provider (OAuth2 only)
* @var array|null $SCOPES - a set of scopes for the current provider
*/
$CFGDIR ??= __DIR__.'/../.config';
$ENVFILE ??= '.env_example';
$LOGLEVEL ??= 'info';
$ENVFILE ??= '.env';
$LOGLEVEL ??= LogLevel::INFO;
$PARAMS ??= null;
$SCOPES ??= null;

$httpFactory = new HttpFactory;
$http = new Client([
// invoke the PSR-17 and PSR-18 instances
$httpFactory = new \GuzzleHttp\Psr7\HttpFactory;
$http = new \GuzzleHttp\Client([
'verify' => $CFGDIR.'/cacert.pem',
'headers' => [
'User-Agent' => OAuthInterface::USER_AGENT,
],
]);

/*
$httpFactory = new \chillerlan\HTTP\Psr7\HttpFactory;
$http = new \chillerlan\HTTP\CurlClient($httpFactory, new \chillerlan\HTTP\HTTPOptions([
'ca_info' => $CFGDIR.'/cacert.pem',
'user_agent' => OAuthInterface::USER_AGENT,
]));
*/

$factory = new OAuthExampleProviderFactory(
new OAuthProviderFactory($http, $httpFactory, $httpFactory, $httpFactory),
$CFGDIR,
Expand Down
9 changes: 3 additions & 6 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
$CFGDIR = __DIR__.'/../.config/';
// the name of the .env file
$ENVFILE = '.env';
// an optional prefix for the provider variables in the .env
$ENVVAR = null;
// optional scopes for OAuth2 providers
// additional params to pass to getAuthorizationURL()
$PARAMS = null;
// optional scopes
$SCOPES = null;

require_once __DIR__.'/../examples/get-token/GitHub.php';



2 changes: 1 addition & 1 deletion src/OAuthProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
public function getProvider(
string $providerFQN,
SettingsContainerInterface|OAuthOptions $options = new OAuthOptions,
OAuthStorageInterface|null $storage = new MemoryStorage,
OAuthStorageInterface $storage = new MemoryStorage,
):OAuthInterface|OAuth1Interface|OAuth2Interface{

if(!class_exists($providerFQN)){
Expand Down

0 comments on commit 647a43d

Please sign in to comment.