Skip to content

Commit 443750a

Browse files
authored
bugfix (#207)
* add Tapd channel * bugfix * wip
1 parent 4c94d6c commit 443750a

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/Providers/Tapd.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Overtrue\Socialite\Providers;
44

5+
use GuzzleHttp\Psr7\Stream;
6+
use Overtrue\Socialite\Exceptions\AuthorizeFailedException;
57
use Overtrue\Socialite\Exceptions\BadRequestException;
68
use Overtrue\Socialite\User;
79

@@ -139,11 +141,45 @@ protected function mapUserToObject(array $user): User
139141
}
140142

141143
return new User([
142-
'id' => $user['data']['id'],
143-
'nickname' => $user['data']['nick'],
144-
'name' => $user['data']['name'],
145-
'email' => '',
146-
'avatar' => $user['data']['avatar'],
144+
'id' => $user['data']['id'] ?? null,
145+
'nickname' => $user['data']['nick'] ?? null,
146+
'name' => $user['data']['name'] ?? null,
147+
'email' => $user['data']['email'] ?? null,
148+
'avatar' => $user['data']['avatar'] ?? null,
147149
]);
148150
}
151+
152+
/**
153+
* @param array|string $response
154+
*
155+
* @return mixed
156+
* @return array
157+
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
158+
*
159+
*/
160+
protected function normalizeAccessTokenResponse($response): array
161+
{
162+
if ($response instanceof Stream) {
163+
$response->rewind();
164+
$response = $response->getContents();
165+
}
166+
167+
if (\is_string($response)) {
168+
$response = json_decode($response, true) ?? [];
169+
}
170+
171+
if (!\is_array($response)) {
172+
throw new AuthorizeFailedException('Invalid token response', [$response]);
173+
}
174+
175+
if (empty($response['data'][$this->accessTokenKey])) {
176+
throw new AuthorizeFailedException('Authorize Failed: ' . json_encode($response, JSON_UNESCAPED_UNICODE), $response);
177+
}
178+
179+
return $response + [
180+
'access_token' => $response['data'][$this->accessTokenKey],
181+
'refresh_token' => $response['data'][$this->refreshTokenKey] ?? null,
182+
'expires_in' => \intval($response['data'][$this->expiresInKey] ?? 0),
183+
];
184+
}
149185
}

src/SocialiteManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SocialiteManager implements FactoryInterface
2929
Providers\Linkedin::NAME => Providers\Linkedin::class,
3030
Providers\Facebook::NAME => Providers\Facebook::class,
3131
Providers\DingTalk::NAME => Providers\DingTalk::class,
32+
Providers\Tapd::NAME => Providers\Tapd::class,
3233
];
3334

3435
public function __construct(array $config)

0 commit comments

Comments
 (0)