From de962846fcfd069913a89345e892380da808c8d4 Mon Sep 17 00:00:00 2001 From: Ankit Gade Date: Fri, 23 Jul 2021 20:59:44 +0530 Subject: [PATCH] Provide filter for client arguments --- src/Utils/GoogleClient.php | 34 ++++++++++++++++------- tests/php/Unit/Utils/GoogleClientTest.php | 11 ++++++++ vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 8 +++--- vendor/composer/autoload_static.php | 8 +++--- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/Utils/GoogleClient.php b/src/Utils/GoogleClient.php index 556c74da..ea78f887 100644 --- a/src/Utils/GoogleClient.php +++ b/src/Utils/GoogleClient.php @@ -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 ); } /** diff --git a/tests/php/Unit/Utils/GoogleClientTest.php b/tests/php/Unit/Utils/GoogleClientTest.php index 6e3e1d36..8a3b24bb 100644 --- a/tests/php/Unit/Utils/GoogleClientTest.php +++ b/tests/php/Unit/Utils/GoogleClientTest.php @@ -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() ); diff --git a/vendor/autoload.php b/vendor/autoload.php index 91b16c43..2a197b7d 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit21e7e90cc7311a71bc3ed151a4019e8f::getLoader(); +return ComposerAutoloaderIniteae54bb1498c1e8cc3f4af6a43a932c6::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index e2b275ac..721aff6d 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit21e7e90cc7311a71bc3ed151a4019e8f +class ComposerAutoloaderIniteae54bb1498c1e8cc3f4af6a43a932c6 { private static $loader; @@ -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) { diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 7ec3ac2a..a36f2b1e 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit21e7e90cc7311a71bc3ed151a4019e8f +class ComposerStaticIniteae54bb1498c1e8cc3f4af6a43a932c6 { public static $prefixLengthsPsr4 = array ( 'R' => @@ -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); }