authenticate(baseUrl: string,options: AuthOptions): Promise<AuthResult | null>
Authenticates with a TP-Link router and returns session context.
Performs the following steps:
- Fetches router info from the login page
- Retrieves RSA public key for encryption
- Creates encryption instance with AES + RSA
- Checks if already logged in
- Performs login to get session ID
- Retrieves security token for API calls
Basic authentication
Basic authentication
import { authenticate } from "./authenticate.ts"; const auth = await authenticate("http://192.168.1.1", { password: "admin", }); if (auth) { // Use auth.encryption, auth.sessionId, auth.tokenId for API calls }
Base URL of the router (e.g., "http://192.168.1.1")
options: AuthOptions
Authentication options including password
Promise<AuthResult | null>
Authentication result with encryption context, or null if login failed