Skip to content

Commit 0a4d2bd

Browse files
committed
Fetch user if token retrieval is successful
1 parent c72ecf7 commit 0a4d2bd

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Discord/Endpoints/OAuth2Endpoint.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ private function get(
103103
/** @var OAuth2Authenticator $OAA */
104104

105105
if (isset($params['code'], $params['state'])) {
106-
/*$token =*/ $OAA->getToken($response, $headers, $body, $params['code'], $params['state']);
106+
if ($OAA->getToken($response, $headers, $body, $params['code'], $params['state'])) {
107+
$OAA->getUser();
108+
}
107109
return;
108110
}
109111
if (isset($params['login'])) {
@@ -118,10 +120,10 @@ private function get(
118120
$OAA->removeToken($response, $headers, $body);
119121
return;
120122
}
121-
if (isset($params['user']) && $OAA->isAuthed()) {
123+
if (isset($params['user']) && $user = $OAA->getUser()) {
122124
$response = Response::STATUS_OK;
123125
$headers = ['Content-Type' => 'application/json'];
124-
$body = json_encode($OAA->getUser());
126+
$body = json_encode($user);
125127
return;
126128
}
127129
}

src/SS14/Endpoints/OAuth2Endpoint.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ private function get(
103103
/** @var OAuth2Authenticator $OAA */
104104

105105
if (isset($params['code'], $params['state'])) {
106-
/*$token =*/ $OAA->getToken($response, $headers, $body, $params['code'], $params['state']);
106+
if ($OAA->getToken($response, $headers, $body, $params['code'], $params['state'])) {
107+
$OAA->getUser();
108+
}
107109
return;
108110
}
109111
if (isset($params['login'])) {
@@ -118,6 +120,12 @@ private function get(
118120
$OAA->removeToken($response, $headers, $body);
119121
return;
120122
}
123+
if (isset($params['user']) && $user = $OAA->getUser()) {
124+
$response = Response::STATUS_OK;
125+
$headers = ['Content-Type' => 'application/json'];
126+
$body = json_encode($user);
127+
return;
128+
}
121129
}
122130

123131
/**

0 commit comments

Comments
 (0)