Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'refs/heads/dev'

+44 -1
+25 -1
src/Data/AccessToken.php
··· 2 2 3 3 namespace SocialDept\AtpClient\Data; 4 4 5 + use Carbon\Carbon; 5 6 use SocialDept\AtpClient\Enums\AuthType; 6 7 7 8 class AccessToken ··· 40 41 } 41 42 42 43 // Legacy createSession format (app passwords have full access) 44 + // Parse expiry from JWT since createSession doesn't return expiresIn 45 + $expiresAt = self::parseJwtExpiry($data['accessJwt']) ?? now()->addHour(); 46 + 43 47 return new self( 44 48 accessJwt: $data['accessJwt'], 45 49 refreshJwt: $data['refreshJwt'], 46 50 did: $data['did'], 47 - expiresAt: now()->addSeconds($data['expiresIn'] ?? 300), 51 + expiresAt: $expiresAt, 48 52 handle: $data['handle'] ?? $handle, 49 53 issuer: $issuer, 50 54 scope: ['atproto', 'transition:generic', 'transition:email'], 51 55 authType: AuthType::Legacy, 52 56 ); 57 + } 58 + 59 + /** 60 + * Parse the expiry timestamp from a JWT's payload. 61 + */ 62 + protected static function parseJwtExpiry(string $jwt): ?\DateTimeInterface 63 + { 64 + $parts = explode('.', $jwt); 65 + 66 + if (count($parts) !== 3) { 67 + return null; 68 + } 69 + 70 + $payload = json_decode(base64_decode(strtr($parts[1], '-_', '+/')), true); 71 + 72 + if (! isset($payload['exp'])) { 73 + return null; 74 + } 75 + 76 + return Carbon::createFromTimestamp($payload['exp']); 53 77 } 54 78 }
+16
src/Events/LegacyUserAuthenticated.php
··· 1 + <?php 2 + 3 + namespace SocialDept\AtpClient\Events; 4 + 5 + use Illuminate\Foundation\Events\Dispatchable; 6 + use Illuminate\Queue\SerializesModels; 7 + use SocialDept\AtpClient\Data\AccessToken; 8 + 9 + class LegacyUserAuthenticated 10 + { 11 + use Dispatchable, SerializesModels; 12 + 13 + public function __construct( 14 + public readonly AccessToken $token, 15 + ) {} 16 + }
+3
src/Session/SessionManager.php
··· 8 8 use SocialDept\AtpClient\Contracts\CredentialProvider; 9 9 use SocialDept\AtpClient\Contracts\KeyStore; 10 10 use SocialDept\AtpClient\Data\AccessToken; 11 + use SocialDept\AtpClient\Events\LegacyUserAuthenticated; 11 12 use SocialDept\AtpClient\Events\TokenRefreshed; 12 13 use SocialDept\AtpClient\Events\TokenRefreshing; 13 14 use SocialDept\AtpClient\Exceptions\AuthenticationException; ··· 102 103 103 104 // Store credentials using DID as key 104 105 $this->credentials->storeCredentials($did, $token); 106 + 107 + event(new LegacyUserAuthenticated($token)); 105 108 106 109 return $this->createSession($did); 107 110 }