Skip to content

Commit

Permalink
hotfix(backend): oauth fixes for GitHub and Google
Browse files Browse the repository at this point in the history
  • Loading branch information
TyIsI committed Jan 16, 2025
1 parent 8224ca7 commit 206f6f9
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 397 deletions.
3 changes: 2 additions & 1 deletion app/security/oauth/OAuthHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use vhs\web\HttpServer;

class OAuthHelper {
/** @var AbstractProvider */
private $provider;
/** @var HttpServer */
private $server;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function processToken() {
'code' => $_GET['code']
]);
if (!is_null($token)) {
$this->userDetails = $this->provider->getUserDetails($token);
$this->userDetails = $this->provider->getResourceOwner($token);

return $this->userDetails;
}
Expand Down
5 changes: 3 additions & 2 deletions app/security/oauth/modules/GithubOAuthHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getUrl() {
public function handle(HttpServer $server) {
$host = OauthHelper::redirectHost();

$action = $_GET['action'] ?: 'link';
$action = isset($_GET['action']) ? $_GET['action'] : 'link';

$provider = new Github([
'clientId' => OAUTH_GITHUB_CLIENT,
Expand All @@ -37,11 +37,12 @@ public function handle(HttpServer $server) {
if (!isset($_GET['code'])) {
$oauthHelper->requestAuth();
} else {
/** @var GithubResourceOwner | null */
$userDetails = $oauthHelper->processToken();
}

if ($_GET['action'] == 'link' && !is_null($userDetails)) {
$oauthHelper->linkAccount($userDetails->uid, 'github', 'GitHub Account for ' . $userDetails->nickname);
$oauthHelper->linkAccount($userDetails->getId(), 'github', 'GitHub Account for ' . $userDetails->getNickname());

$server->clear();
$server->redirect('/index.html#/profile/');
Expand Down
3 changes: 2 additions & 1 deletion app/security/oauth/modules/GoogleOAuthHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public function handle(HttpServer $server) {
if (!isset($_GET['code'])) {
$oauthHelper->requestAuth();
} else {
/** @var GoogleUser | null */
$userDetails = $oauthHelper->processToken();
}

if ($_GET['action'] == 'link' && !is_null($userDetails)) {
$oauthHelper->linkAccount($userDetails->uid, 'google', 'Google Account for ' . $userDetails->name);
$oauthHelper->linkAccount($userDetails->getId(), 'google', 'Google Account for ' . $userDetails->getName());

$server->clear();
$server->redirect('/index.html#/profile/');
Expand Down
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"require": {
"aws/aws-sdk-php": "3.*",
"nicmart/string-template": "~0.1",
"league/oauth2-client": "0.10.*",
"php-amqplib/php-amqplib": "2.5.*",
"stripe/stripe-php": "7.128.0"
"aws/aws-sdk-php": "3.336.8",
"nicmart/string-template": "0.1.3",
"league/oauth2-client": "2.8.0",
"php-amqplib/php-amqplib": "2.5.2",
"stripe/stripe-php": "7.128.0",
"league/oauth2-github": "3.1.1",
"league/oauth2-google": "4.0.1"
},
"require-dev": {
"phpunit/phpunit": "^11",
"friendsofphp/php-cs-fixer": "^v3"
"phpunit/phpunit": "11.5.3",
"friendsofphp/php-cs-fixer": "v3.68.0"
}
}
Loading

0 comments on commit 206f6f9

Please sign in to comment.