Sync your WordPress posts to standard.site records on your PDS
at main 66 lines 1.4 kB view raw
1<?php 2declare(strict_types=1); 3/** 4 * DPoP nonce storage using WordPress transients. 5 * 6 * @package Wireservice 7 */ 8 9namespace Wireservice; 10 11if (! defined('ABSPATH')) { 12 exit; 13} 14 15use danielburger1337\OAuth2\DPoP\NonceStorage\NonceStorageInterface; 16 17class NonceStorage implements NonceStorageInterface 18{ 19 /** 20 * Transient prefix. 21 * 22 * @var string 23 */ 24 private const PREFIX = "wireservice_dpop_nonce_"; 25 26 /** 27 * Nonce TTL in seconds. 28 * 29 * @var int 30 */ 31 private const TTL = 300; 32 33 /** 34 * Get the current DPoP-Nonce for an upstream server. 35 * 36 * @param string $key The storage key. 37 * @return string|null The nonce or null. 38 */ 39 public function getCurrentNonce(string $key): ?string 40 { 41 $nonce = get_transient(self::PREFIX . $this->hashKey($key)); 42 return $nonce !== false ? $nonce : null; 43 } 44 45 /** 46 * Store a new DPoP-Nonce from an upstream server. 47 * 48 * @param string $key The storage key. 49 * @param string $nonce The nonce to store. 50 */ 51 public function storeNextNonce(string $key, string $nonce): void 52 { 53 set_transient(self::PREFIX . $this->hashKey($key), $nonce, self::TTL); 54 } 55 56 /** 57 * Hash the key to a safe transient name. 58 * 59 * @param string $key The storage key. 60 * @return string The hashed key. 61 */ 62 private function hashKey(string $key): string 63 { 64 return substr(md5($key), 0, 32); 65 } 66}