Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Tests\Support;
use Psr\Http\Message\RequestInterface;use Wotnak\Atproto\Client\RefreshableAuthenticatedSessionInterface;use Wotnak\Atproto\Client\RememberingDpopNonceAuthenticatedSessionInterface;
final class TestRefreshableDpopSession implements RefreshableAuthenticatedSessionInterface, RememberingDpopNonceAuthenticatedSessionInterface {
public ?string $rememberedNonce = NULL;
public int $refreshCount = 0;
public bool $invalidated = FALSE;
private string $accessToken = 'expired-token';
public function __construct( private readonly bool $refreshSucceeds = TRUE, private readonly ?\Throwable $refreshFailure = NULL, ) {}
public function getAccessToken(): string { return $this->accessToken; }
public function sign(RequestInterface $request): RequestInterface { return $this->signWithDpopNonce($request, $this->rememberedNonce); }
public function signWithDpopNonce(RequestInterface $request, ?string $nonce): RequestInterface { return $request ->withHeader('Authorization', 'DPoP ' . $this->accessToken) ->withHeader('X-DPoP-Nonce', $nonce ?? ''); }
public function getSubjectDid(): string { return 'did:plc:abc'; }
public function getPdsUrl(): string { return 'https://pds.example'; }
public function rememberDpopNonce(?string $nonce): void { $this->rememberedNonce = $nonce; }
public function refresh(): bool { $this->refreshCount++; if ($this->refreshFailure !== NULL) { throw $this->refreshFailure; } if (!$this->refreshSucceeds) { return FALSE; } $this->accessToken = 'refreshed-token'; return TRUE; }
public function invalidate(): void { $this->invalidated = TRUE; }
}