redis->setex($this->buildKey($codeId), self::USED_CODE_TTL, '1'); } /** * The library checks the code at the beginning of the exchange and revokes it only at the end. * To prevent the concurrent exchange of the same code, the code is atomically marked as used during the check. */ public function isAuthCodeRevoked(string $codeId): bool { return Yii::$app->redis->set($this->buildKey($codeId), '1', 'EX', self::USED_CODE_TTL, 'NX') !== true; } private function buildKey(string $codeId): string { return "oauth:auth-codes:used:{$codeId}"; } }