Reviewer · Security
Explicit per-method auth requests
Avoid routing all authentication flows through a single generic, loosely-typed method (e.g., `auth.authenticate(args)`) that accepts a grab-bag of arguments for every backend. This obscures exactly what credentials/data are sent for each auth method, making it hard to audit and increasing the risk of passing unnecessary or incorrect data to the...
Avoid routing all authentication flows through a single generic, loosely-typed method (e.g., auth.authenticate(args)) that accepts a grab-bag of arguments for every backend. This obscures exactly what credentials/data are sent for each auth method, making it hard to audit and increasing the risk of passing unnecessary or incorrect data to the authentication layer.
Instead, implement a dedicated, strongly-typed login/request method for each authentication method (e.g., loginJwt, loginOidc), each responsible for building and sending only the data it actually needs, and returning a normalized response. Have a single loginRequest dispatcher call the appropriate method based on auth type, so error handling and response normalization stay centralized while the data flow for each backend remains explicit and traceable.
Example:
async loginRequest(formData: JwtLoginData) {
return this.isOIDC ? await this.loginOidc() : await this.loginJwt(formData);
}
async loginJwt(formData: JwtLoginData) {
const { path, jwt, role } = formData;
const { auth } = await this.api.auth.jwtLogin(path, { jwt, role });
return this.normalizeAuthResponse(auth, { path, tokenKey: 'clientToken', ttlKey: 'leaseDuration' });
}
This pattern ensures that each auth method’s required fields are explicit and type-checked, reduces the attack surface from unvalidated/untyped auth payloads, and keeps error handling for failed authentication attempts centralized and consistent across all login methods.