Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Providers/Alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public function tokenFromCode(string $code): array
throw new Exceptions\BadRequestException((string) $responseInstance->getBody());
}

if (empty($response['alipay_system_oauth_token_response'])) {
throw new Exceptions\AuthorizeFailedException('Authorization failed: missing alipay_system_oauth_token_response in response', $response);
}

return $this->normalizeAccessTokenResponse($response['alipay_system_oauth_token_response']);
}

Expand Down
10 changes: 7 additions & 3 deletions src/Providers/DingTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ public function userFromCode(string $code): Contracts\UserInterface
throw new Exceptions\BadRequestException((string) $responseInstance->getBody());
}

if (empty($response['user_info'])) {
Copy link
Owner

@overtrue overtrue Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是应该判断 $response['user_info'][Contracts\ABNF_OPEN_ID] @copilot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

您说得对!我已经在DingTalk.php中添加了对 $response['user_info'][Contracts\ABNF_OPEN_ID] 的具体验证。现在代码会先检查 user_info 存在,然后专门检查 open_id 字段是否存在,这样提供更准确的错误信息。提交: 1098be5

throw new Exceptions\AuthorizeFailedException('Authorization failed: missing user_info in response', $response);
}

return new User([
Contracts\ABNF_NAME => $response['user_info']['nick'],
Contracts\ABNF_NICKNAME => $response['user_info']['nick'],
Contracts\ABNF_ID => $response['user_info'][Contracts\ABNF_OPEN_ID],
Contracts\ABNF_NAME => $response['user_info']['nick'] ?? null,
Contracts\ABNF_NICKNAME => $response['user_info']['nick'] ?? null,
Contracts\ABNF_ID => $response['user_info'][Contracts\ABNF_OPEN_ID] ?? null,
]);
}
}
4 changes: 4 additions & 0 deletions src/Providers/DouYin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public function tokenFromCode(string $code): array
throw new Exceptions\AuthorizeFailedException('Invalid token response', $body);
}

if (empty($body['data'][Contracts\ABNF_OPEN_ID] ?? null)) {
throw new Exceptions\AuthorizeFailedException('Authorization failed: missing open_id in token response', $body);
}

$this->withOpenId($body['data'][Contracts\ABNF_OPEN_ID]);

return $this->normalizeAccessTokenResponse($body['data']);
Expand Down
3 changes: 3 additions & 0 deletions src/Providers/OpenWeWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public function userFromCode(string $code): Contracts\UserInterface
$user = $this->getUser($this->getSuiteAccessToken(), $code);

if ($this->detailed) {
if (empty($user['user_ticket'])) {
throw new Exceptions\AuthorizeFailedException('Authorization failed: missing user_ticket in response', $user);
}
$user = \array_merge($user, $this->getUserByTicket($user['user_ticket']));
}

Expand Down
4 changes: 4 additions & 0 deletions src/Providers/QQ.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@

$me = $this->fromJsonBody($response);

if (empty($me['openid'])) {
throw new AuthorizeFailedException('Authorization failed: missing openid in token response', $me);
}

$response = $this->getHttpClient()->get($this->baseUrl.'/user/get_user_info', [
'query' => [
Contracts\RFC6749_ABNF_ACCESS_TOKEN => $token,
Expand All @@ -94,7 +98,7 @@

return $user + [
'unionid' => $me['unionid'] ?? null,
'openid' => $me['openid'] ?? null,

Check failure on line 101 in src/Providers/QQ.php

View workflow job for this annotation

GitHub Actions / PHPStan

Offset 'openid' on array on left side of ?? always exists and is not nullable.

Check failure on line 101 in src/Providers/QQ.php

View workflow job for this annotation

GitHub Actions / PHPStan

Offset 'openid' on array on left side of ?? always exists and is not nullable.
];
}

Expand Down
7 changes: 7 additions & 0 deletions src/Providers/WeWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function userFromCode(string $code): Contracts\UserInterface
$user = $this->getUser($token, $code);

if ($this->detailed) {
if (empty($user['UserId'])) {
throw new Exceptions\AuthorizeFailedException('Authorization failed: missing UserId in user response', $user);
}
$user = $this->getUserById($user['UserId']);
}

Expand Down Expand Up @@ -203,6 +206,10 @@ protected function requestApiAccessToken(): string
throw new Exceptions\AuthorizeFailedException((string) $responseInstance->getBody(), $response);
}

if (empty($response[Contracts\RFC6749_ABNF_ACCESS_TOKEN])) {
throw new Exceptions\AuthorizeFailedException('Authorization failed: missing access_token in response', $response);
}

return $response[Contracts\RFC6749_ABNF_ACCESS_TOKEN];
}

Expand Down
Loading
Loading