Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Auth\OAuth;
use Psr\Http\Message\RequestInterface;use Wotnak\Atproto\Client\DpopNonceAwareAuthenticatedRequestSignerInterface;use Wotnak\Atproto\Client\RememberingDpopNonceAuthenticatedSessionInterface;
/** * OAuth session data plus the request signer needed for DPoP-bound requests. * * @api */final class OAuthAuthenticatedSession implements RememberingDpopNonceAuthenticatedSessionInterface {
public function __construct( private OAuthSession $session, private ?DpopNonceAwareAuthenticatedRequestSignerInterface $signer = NULL, ) {}
/** * Returns the access token. */ public function getAccessToken(): string { return $this->session->getAccessToken(); }
/** * Returns the current OAuth session, including remembered nonces. */ public function getSession(): OAuthSession { return $this->session; }
/** * Adds authentication proof to the request. */ public function sign(RequestInterface $request): RequestInterface { return $this->signWithDpopNonce($request, $this->session->resourceServerNonce); }
/** * Signs a request with the supplied DPoP nonce. */ public function signWithDpopNonce(RequestInterface $request, ?string $nonce): RequestInterface { if ($this->signer !== NULL) { return $this->signer->signWithDpopNonce($request, $nonce); } if ($this->session->dpopPrivateJwk === NULL) { throw new \InvalidArgumentException('OAuth session is missing DPoP key material.'); }
$dpopKey = DpopPrivateKey::fromJwk($this->session->dpopPrivateJwk, $this->session->dpopAlgorithm); return new DpopRequestSigner(new DpopProofFactory($dpopKey), $this->session, $nonce)->sign($request); }
/** * Returns the subject DID. */ public function getSubjectDid(): string { return $this->session->did; }
/** * Returns the PDS URL. */ public function getPdsUrl(): ?string { return $this->session->pdsUrl; }
/** * Stores the latest DPoP nonce in the session. */ public function rememberDpopNonce(?string $nonce): void { $this->session = $this->session->withResourceServerNonce($nonce); }
}