Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Telegram resource owner #1966

Merged
merged 11 commits into from
Dec 5, 2023
Prev Previous commit
Next Next commit
Telegram resource owner fixes
  • Loading branch information
zorn-v committed Nov 30, 2023
commit 1879d5dff9eef477a4402ae8b1c85a6f5f743df4
9 changes: 6 additions & 3 deletions src/OAuth/ResourceOwner/TelegramResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handles(Request $request)

public function getAccessToken(Request $request, $redirectUri, array $extraParameters = [])
{
$token = $request->query->get('code');
$token = $request->query->get('code', '');
$token = str_pad(strtr($token, '-_', '+/'), strlen($token) % 4, '=', STR_PAD_RIGHT);
$authData = json_decode(base64_decode($token), true);
if (empty($authData['hash'])) {
Expand All @@ -70,8 +70,11 @@ public function getAccessToken(Request $request, $redirectUri, array $extraParam
$checkHash = $authData['hash'];
unset($authData['hash']);
ksort($authData);
array_walk($authData, function (&$value, $key) {$value = $key.'='.$value;});
$dataCheckStr = implode("\n", $authData);
$dataCheckStr = '';
foreach ($authData as $k => $v) {
$dataCheckStr .= sprintf("\n%s=%s", $k, $v);
}
$dataCheckStr = substr($dataCheckStr, 1);
$secretKey = hash('sha256', $botToken, true);
$hash = hash_hmac('sha256', $dataCheckStr, $secretKey);
if ($hash !== $checkHash) {
Expand Down