From dce91d04615099936dbcea4d33da0c57e0751699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz> Date: Wed, 21 Sep 2022 19:25:59 +0200 Subject: [PATCH] Chobotnice callback --- VERSION | 2 +- pirati.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/VERSION b/VERSION index 17e51c3..0ea3a94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.1 +0.2.0 diff --git a/pirati.php b/pirati.php index 670cb74..e84ca70 100644 --- a/pirati.php +++ b/pirati.php @@ -42,7 +42,7 @@ class pirati extends \phpbb\auth\provider\oauth\service\base $this->config = $config; $this->request = $request; - + global $phpbb_container; $language = $phpbb_container->get('language'); $language->add_lang(array('common', 'acp/common'), 'pirates/pirid'); @@ -88,7 +88,6 @@ class pirati extends \phpbb\auth\provider\oauth\service\base try { - // This was a callback request, get the token $this->service_provider->requestAccessToken($this->request->variable('code', '')); } catch (\OAuth\Common\Http\Exception\TokenResponseException $e) @@ -106,7 +105,6 @@ class pirati extends \phpbb\auth\provider\oauth\service\base throw new \phpbb\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST'); } - // Prevent SQL error if (!isset($result['preferred_username'])) { throw new \phpbb\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_RETURN_ERROR'); @@ -128,7 +126,6 @@ class pirati extends \phpbb\auth\provider\oauth\service\base try { - // Send a request with it $result = (array) json_decode($this->service_provider->request('protocol/openid-connect/userinfo'), true); } catch (\OAuth\Common\Exception\Exception $e) @@ -136,13 +133,17 @@ class pirati extends \phpbb\auth\provider\oauth\service\base throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST'); } - // Prevent SQL error if (!isset($result['preferred_username'])) { - throw new exception('AUTH_PROVIDER_OAUTH_RETURN_ERROR'); + throw new \phpbb\auth\provider\oauth\service\exception('AUTH_PROVIDER_OAUTH_RETURN_ERROR'); } + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://chobotnice.pirati.cz/import-person/" . $result['sub'] . "/"); + curl_exec($ch); + curl_close($ch); + return $result['sub']; - + } } -- GitLab