Skip to content

Commit

Permalink
implement refreshToken() for feishu/lark (#258)
Browse files Browse the repository at this point in the history
* implement refreshToken() for feishu/lark

* fix for pint

Co-authored-by: bostin.wang <[email protected]>
  • Loading branch information
bostin and bostin.wang committed Jan 10, 2023
1 parent 3cd9501 commit e55fdf5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Providers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function tokenFromCode(string $code): array
/**
* @throws Exceptions\MethodDoesNotSupportException
*/
public function refreshToken(string $refreshToken): void
public function refreshToken(string $refreshToken): mixed
{
throw new Exceptions\MethodDoesNotSupportException('refreshToken does not support.');
}
Expand Down
27 changes: 27 additions & 0 deletions src/Providers/FeiShu.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ protected function getTokenFromCode(string $code): array
return $this->normalizeAccessTokenResponse($response['data']);
}

protected function getRefreshTokenUrl(): string
{
return $this->baseUrl.'/authen/v1/refresh_access_token';
}

/**
* @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/authen-v1/authen/refresh_access_token
*/
public function refreshToken(string $refreshToken): array
{
$this->configAppAccessToken();
$responseInstance = $this->getHttpClient()->post($this->getRefreshTokenUrl(), [
'json' => [
'app_access_token' => $this->config->get('app_access_token'),
Contracts\RFC6749_ABNF_REFRESH_TOKEN => $refreshToken,
Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_REFRESH_TOKEN,
],
]);
$response = $this->fromJsonBody($responseInstance);

if (empty($response['data'] ?? null)) {
throw new Exceptions\AuthorizeFailedException('Invalid token response', $response);
}

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

/**
* @throws Exceptions\BadRequestException
*/
Expand Down
1 change: 1 addition & 0 deletions src/Providers/Lark.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
class Lark extends FeiShu
{
public const NAME = 'lark';

protected string $baseUrl = 'https://open.larksuite.com/open-apis';
}

0 comments on commit e55fdf5

Please sign in to comment.