store->selectCollection(self::COLLECTION_NAME)->findOne([ 'tid' => $tenant, 'identifier' => $identifier ]); if (!$entry) { return null; } return (array)$entry; } /** * Create a new credential record * * @param string $tenant Tenant identifier * @param string $identifier User identity * @param string $encryptedSecret Encrypted password * @return bool Whether creation was successful */ public function create(string $tenant, string $identifier, string $encryptedSecret): bool { $result = $this->store->selectCollection(self::COLLECTION_NAME)->insertOne([ 'tid' => $tenant, 'identifier' => $identifier, 'secret' => $encryptedSecret, 'created_at' => time(), 'updated_at' => time(), ]); return $result->isAcknowledged(); } /** * Update credential secret * * @param string $tenant Tenant identifier * @param string $identifier User identity * @param string $encryptedSecret New encrypted password * @return bool Whether update was successful */ public function updateSecret(string $tenant, string $identifier, string $encryptedSecret): bool { $result = $this->store->selectCollection(self::COLLECTION_NAME)->updateOne( ['tid' => $tenant, 'identifier' => $identifier], ['$set' => [ 'secret' => $encryptedSecret, 'updated_at' => time(), ]] ); return $result->isAcknowledged(); } /** * Delete credential record * * @param string $tenant Tenant identifier * @param string $identifier User identity * @return bool Whether deletion was successful */ public function delete(string $tenant, string $identifier): bool { $result = $this->store->selectCollection(self::COLLECTION_NAME)->deleteOne([ 'tid' => $tenant, 'identifier' => $identifier ]); return $result->isAcknowledged(); } /** * Check if credential exists for identifier * * @param string $tenant Tenant identifier * @param string $identifier User identity * @return bool Whether credential exists */ public function exists(string $tenant, string $identifier): bool { return $this->fetchByIdentifier($tenant, $identifier) !== null; } }