Skip to content

Commit

Permalink
Merge pull request #87 from rtCamp/feature/client-args-filter
Browse files Browse the repository at this point in the history
Provide filter for client arguments: rtcamp.google_client_args
  • Loading branch information
pdclark authored Jul 23, 2021
2 parents f6b36d9 + de96284 commit 5fd2b9c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
34 changes: 24 additions & 10 deletions src/Utils/GoogleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,32 @@ public function authorization_url(): string {
'rtcamp.google_scope'
);

/**
* Filter the scopes.
*
* @param array $scope List of scopes.
*/
$scope = apply_filters( 'rtcamp.google_scope', $scope );

return self::AUTHORIZE_URL . '?' . http_build_query(
[
'client_id' => $this->client_id,
'redirect_uri' => $this->gt_redirect_url(),
'state' => $this->state(),
'scope' => implode( ' ', $scope ),
'access_type' => 'online',
'response_type' => 'code',
]
);
$client_args = [
'client_id' => $this->client_id,
'redirect_uri' => $this->gt_redirect_url(),
'state' => $this->state(),
'scope' => implode( ' ', $scope ),
'access_type' => 'online',
'response_type' => 'code',
];

/**
* Filter the arguments for sending in query.
*
* This is useful in cases for example: choosing the correct prompt.
*
* @param array $client_args List of query arguments to send to Google OAuth.
*/
$client_args = apply_filters( 'rtcamp.google_client_args', $client_args );

return self::AUTHORIZE_URL . '?' . http_build_query( $client_args );
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/php/Unit/Utils/GoogleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ public function testAuthorizationURL() {
$ghClient->expects( $this->once() )->method( 'state' )->willReturn( 'abcd' );
$ghClient->client_id = 'cid';

$client_args = [
'client_id' => 'cid',
'redirect_uri' => '',
'state' => 'abcd',
'scope' => implode( ' ', $scope ),
'access_type' => 'online',
'response_type' => 'code',
];

WP_Mock::expectFilter( 'rtcamp.google_client_args', $client_args );

$expected = 'https://accounts.google.com/o/oauth2/auth?client_id=cid&redirect_uri=&state=abcd&scope=email+profile+openid&access_type=online&response_type=code';

$this->assertSame( $expected, $ghClient->authorization_url() );
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit21e7e90cc7311a71bc3ed151a4019e8f::getLoader();
return ComposerAutoloaderIniteae54bb1498c1e8cc3f4af6a43a932c6::getLoader();
8 changes: 4 additions & 4 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit21e7e90cc7311a71bc3ed151a4019e8f
class ComposerAutoloaderIniteae54bb1498c1e8cc3f4af6a43a932c6
{
private static $loader;

Expand All @@ -22,15 +22,15 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit21e7e90cc7311a71bc3ed151a4019e8f', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderIniteae54bb1498c1e8cc3f4af6a43a932c6', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit21e7e90cc7311a71bc3ed151a4019e8f', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderIniteae54bb1498c1e8cc3f4af6a43a932c6', 'loadClassLoader'));

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInit21e7e90cc7311a71bc3ed151a4019e8f::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticIniteae54bb1498c1e8cc3f4af6a43a932c6::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit21e7e90cc7311a71bc3ed151a4019e8f
class ComposerStaticIniteae54bb1498c1e8cc3f4af6a43a932c6
{
public static $prefixLengthsPsr4 = array (
'R' =>
Expand Down Expand Up @@ -41,9 +41,9 @@ class ComposerStaticInit21e7e90cc7311a71bc3ed151a4019e8f
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit21e7e90cc7311a71bc3ed151a4019e8f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit21e7e90cc7311a71bc3ed151a4019e8f::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInit21e7e90cc7311a71bc3ed151a4019e8f::$prefixesPsr0;
$loader->prefixLengthsPsr4 = ComposerStaticIniteae54bb1498c1e8cc3f4af6a43a932c6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticIniteae54bb1498c1e8cc3f4af6a43a932c6::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticIniteae54bb1498c1e8cc3f4af6a43a932c6::$prefixesPsr0;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit 5fd2b9c

Please sign in to comment.