Merge pull request 'Bluesky: Set a status when the token refresh failed' (#1578) from heluecht/friendica-addons:bluesky-status into 2024.09-rc

Reviewed-on: https://git.friendi.ca/friendica/friendica-addons/pulls/1578
Reviewed-by: Hypolite Petovan <hypolite@mrpetovan.com>
pull/1582/head
Hypolite Petovan 2024-12-06 22:46:14 +01:00
commit a04d22ad01
1 changed files with 11 additions and 6 deletions

View File

@ -70,8 +70,8 @@ const BLUEKSY_STATUS_TOKEN_FAIL = 13;
/* /*
* (Currently) hard wired paths for Bluesky services * (Currently) hard wired paths for Bluesky services
*/ */
const BLUESKY_APPVIEW_API = 'https://public.api.bsky.app'; // Path to the public Bluesky AppView API.
const BLUESKY_DIRECTORY = 'https://plc.directory'; // Path to the directory server service to fetch the PDS of a given DID const BLUESKY_DIRECTORY = 'https://plc.directory'; // Path to the directory server service to fetch the PDS of a given DID
const BLUESKY_PDS = 'https://bsky.social'; // Path to the personal data server service (PDS) to fetch the DID for a given handle
const BLUESKY_WEB = 'https://bsky.app'; // Path to the web interface with the user profile and posts const BLUESKY_WEB = 'https://bsky.app'; // Path to the web interface with the user profile and posts
const BLUESKY_HOSTNAME = 'bsky.social'; // Host name to be added to the handle if incomplete const BLUESKY_HOSTNAME = 'bsky.social'; // Host name to be added to the handle if incomplete
@ -1984,8 +1984,8 @@ function bluesky_get_did(string $handle, int $uid): string
return $did; return $did;
} }
// And finally we use the default PDS from Bluesky. // And finally we use the AppView API.
$data = bluesky_get(BLUESKY_PDS . '/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle)); $data = bluesky_get(BLUESKY_APPVIEW_API . '/xrpc/com.atproto.identity.resolveHandle?handle=' . urlencode($handle));
if (!empty($data) && !empty($data->did)) { if (!empty($data) && !empty($data->did)) {
Logger::debug('Got DID by system PDS call', ['handle' => $handle, 'did' => $data->did]); Logger::debug('Got DID by system PDS call', ['handle' => $handle, 'did' => $data->did]);
return $data->did; return $data->did;
@ -2021,6 +2021,10 @@ function bluesky_get_user_did(int $uid, bool $refresh = false): ?string
function bluesky_get_user_pds(int $uid): ?string function bluesky_get_user_pds(int $uid): ?string
{ {
if ($uid == 0) {
return BLUESKY_APPVIEW_API;
}
$pds = DI::pConfig()->get($uid, 'bluesky', 'pds'); $pds = DI::pConfig()->get($uid, 'bluesky', 'pds');
if (!empty($pds)) { if (!empty($pds)) {
return $pds; return $pds;
@ -2104,6 +2108,7 @@ function bluesky_refresh_token(int $uid): string
$data = bluesky_post($uid, '/xrpc/com.atproto.server.refreshSession', '', ['Authorization' => ['Bearer ' . $token]]); $data = bluesky_post($uid, '/xrpc/com.atproto.server.refreshSession', '', ['Authorization' => ['Bearer ' . $token]]);
if (empty($data) || empty($data->accessJwt)) { if (empty($data) || empty($data->accessJwt)) {
DI::pConfig()->set($uid, 'bluesky', 'status', BLUEKSY_STATUS_TOKEN_FAIL);
return ''; return '';
} }