From 8709a5693ff7b80fd6a9147bed0971f5a1d5da0b Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Tue, 21 Aug 2018 11:50:02 +0200 Subject: [PATCH 1/8] remove scope from params for google service as they return full urls now instead of 'profile' --- src/services/GoogleOAuth2Service.php | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/services/GoogleOAuth2Service.php b/src/services/GoogleOAuth2Service.php index 37e3d2a..6efdda0 100644 --- a/src/services/GoogleOAuth2Service.php +++ b/src/services/GoogleOAuth2Service.php @@ -12,6 +12,8 @@ namespace nodge\eauth\services; use nodge\eauth\oauth2\Service; +use Yii; +use yii\helpers\Url; /** * Google provider class. @@ -166,4 +168,32 @@ protected function fetchResponseError($response) return null; } } + + /** + * override getCallbackUrl() + * basically its just ignoring 'scope' param for Google, as they return full urls now + * + * @return string + */ + protected function getCallbackUrl() + { + if (isset($_GET['redirect_uri'])) { + $url = $_GET['redirect_uri']; + } + else { + $route = Yii::$app->getRequest()->getQueryParams(); + array_unshift($route, ''); + + // Can not use these params in OAuth2 callbacks + foreach (['code', 'state', 'redirect_uri', 'scope'] as $param) { + if (isset($route[$param])) { + unset($route[$param]); + } + } + + $url = Url::to($route, true); + } + + return $url; + } } \ No newline at end of file From f1f2f8c24b9a53068dc26d6d5072a046414474c7 Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Tue, 9 Oct 2018 10:35:54 +0200 Subject: [PATCH 2/8] add email to attributes --- src/services/GoogleOAuth2Service.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/GoogleOAuth2Service.php b/src/services/GoogleOAuth2Service.php index 6efdda0..6ea405b 100644 --- a/src/services/GoogleOAuth2Service.php +++ b/src/services/GoogleOAuth2Service.php @@ -123,6 +123,10 @@ protected function fetchAttributes() $this->attributes['url'] = $info['link']; } + if (!empty($info['email'])) { + $this->attributes['email'] = $info['email']; + } + /*if (!empty($info['gender'])) $this->attributes['gender'] = $info['gender'] == 'male' ? 'M' : 'F'; From ff6f05eeb508647a4f3ca4bc8e45644de225f517 Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Sun, 31 Mar 2019 23:06:59 +0200 Subject: [PATCH 3/8] rename yii\base\Object to yii\base\BaseObject for PHP 7.2 compatibility --- src/EAuth.php | 4 ++-- src/ServiceBase.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EAuth.php b/src/EAuth.php index 79bb8be..1fe08e2 100644 --- a/src/EAuth.php +++ b/src/EAuth.php @@ -10,7 +10,7 @@ namespace nodge\eauth; use Yii; -use yii\base\Object; +use yii\base\BaseObject; use yii\helpers\ArrayHelper; use yii\helpers\Url; @@ -19,7 +19,7 @@ * * @package application.extensions.eauth */ -class EAuth extends Object +class EAuth extends BaseObject { /** diff --git a/src/ServiceBase.php b/src/ServiceBase.php index 45b9b38..87e2a8b 100644 --- a/src/ServiceBase.php +++ b/src/ServiceBase.php @@ -10,7 +10,7 @@ namespace nodge\eauth; use Yii; -use yii\base\Object; +use yii\base\BaseObject; use yii\helpers\Url; use yii\helpers\ArrayHelper; use OAuth\Common\Http\Uri\Uri; @@ -21,7 +21,7 @@ * * @package application.extensions.eauth */ -abstract class ServiceBase extends Object implements IAuthService +abstract class ServiceBase extends BaseObject implements IAuthService { /** From c2c04a29f8c3b96da92101935ee279cbc3ec116e Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Wed, 19 Jun 2019 12:06:23 +0200 Subject: [PATCH 4/8] remove more parameters as google doesn't accept these --- src/services/GoogleOAuth2Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/GoogleOAuth2Service.php b/src/services/GoogleOAuth2Service.php index 6ea405b..f5a9680 100644 --- a/src/services/GoogleOAuth2Service.php +++ b/src/services/GoogleOAuth2Service.php @@ -189,7 +189,7 @@ protected function getCallbackUrl() array_unshift($route, ''); // Can not use these params in OAuth2 callbacks - foreach (['code', 'state', 'redirect_uri', 'scope'] as $param) { + foreach (['code', 'state', 'redirect_uri', 'scope', 'authuser', 'prompt', 'session_state'] as $param) { if (isset($route[$param])) { unset($route[$param]); } From 8ea1a5b92accd319b4d8c7a08ca08aedad3f7cfc Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Fri, 28 Jun 2019 16:41:12 +0200 Subject: [PATCH 5/8] remove ANY parameter from redirect_uri as google doesn't like it. still pass the service so yii2 builds the correct url --- src/services/GoogleOAuth2Service.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/services/GoogleOAuth2Service.php b/src/services/GoogleOAuth2Service.php index f5a9680..ae3e94c 100644 --- a/src/services/GoogleOAuth2Service.php +++ b/src/services/GoogleOAuth2Service.php @@ -185,15 +185,9 @@ protected function getCallbackUrl() $url = $_GET['redirect_uri']; } else { - $route = Yii::$app->getRequest()->getQueryParams(); + $route = array(); array_unshift($route, ''); - - // Can not use these params in OAuth2 callbacks - foreach (['code', 'state', 'redirect_uri', 'scope', 'authuser', 'prompt', 'session_state'] as $param) { - if (isset($route[$param])) { - unset($route[$param]); - } - } + $route['service'] = $_GET['service']; $url = Url::to($route, true); } From 46d1662549c403adecb7f5d056a5d5a83ad5c39e Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Sat, 13 Jul 2024 15:33:31 +0200 Subject: [PATCH 6/8] numeric_prefix isnt allowed to be null, needs to be a string --- src/oauth/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oauth/HttpClient.php b/src/oauth/HttpClient.php index b581ac3..49f6dd7 100644 --- a/src/oauth/HttpClient.php +++ b/src/oauth/HttpClient.php @@ -154,7 +154,7 @@ protected function prepareRequest() } if (is_array($this->requestBody)) { - $this->requestBody = http_build_query($this->requestBody, null, '&'); + $this->requestBody = http_build_query($this->requestBody, "", '&'); } } From b41a88580dbb1d2458b290bce1577d3377448fb7 Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Sat, 13 Jul 2024 15:40:30 +0200 Subject: [PATCH 7/8] use more up2date oauth lib --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0123f1d..d4361a8 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php": ">=5.4.0", "lib-curl": "*", "yiisoft/yii2": "*", - "lusitanian/oauth": "~0.3.0", + "carlos-mg89/oauth": "*", "nodge/lightopenid": "~1.1.0" }, "extra": { From 086bfd28ec2684a0c38f1b3779aac7aa82dc7ebc Mon Sep 17 00:00:00 2001 From: Nils Hulsch Date: Sat, 13 Jul 2024 15:42:53 +0200 Subject: [PATCH 8/8] Revert "use more up2date oauth lib" This reverts commit b41a88580dbb1d2458b290bce1577d3377448fb7. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d4361a8..0123f1d 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php": ">=5.4.0", "lib-curl": "*", "yiisoft/yii2": "*", - "carlos-mg89/oauth": "*", + "lusitanian/oauth": "~0.3.0", "nodge/lightopenid": "~1.1.0" }, "extra": {