2020-11-11 19:08:33 +01:00
|
|
|
import {Request, Response} from "express";
|
2020-12-04 14:42:09 +01:00
|
|
|
import {Session} from "express-session";
|
2020-11-11 19:08:33 +01:00
|
|
|
|
2021-05-03 19:29:22 +02:00
|
|
|
import AuthProof from "./AuthProof.js";
|
|
|
|
import User from "./models/User.js";
|
|
|
|
|
2020-11-11 19:08:33 +01:00
|
|
|
|
|
|
|
export default interface AuthMethod<P extends AuthProof<User>> {
|
|
|
|
/**
|
|
|
|
* @return A unique name.
|
|
|
|
*/
|
|
|
|
getName(): string;
|
|
|
|
|
2020-11-16 11:43:14 +01:00
|
|
|
/**
|
|
|
|
* Used for automatic auth method detection. Won't affect forced auth method.
|
|
|
|
*
|
|
|
|
* @return {@code 0} if the request is not conform to this auth method, otherwise the exact count of matching
|
|
|
|
* fields.
|
|
|
|
*/
|
|
|
|
getWeightForRequest(req: Request): number;
|
|
|
|
|
2020-11-11 19:08:33 +01:00
|
|
|
findUserByIdentifier(identifier: string): Promise<User | null>;
|
|
|
|
|
2020-12-04 14:42:09 +01:00
|
|
|
getProofsForSession?(session: Session): Promise<P[]>;
|
2020-11-11 19:08:33 +01:00
|
|
|
|
|
|
|
getProofsForRequest?(req: Request): Promise<P[]>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {@code true} if interrupted, {@code false} otherwise.
|
|
|
|
*/
|
|
|
|
interruptAuth?(req: Request, res: Response): Promise<boolean>;
|
|
|
|
|
|
|
|
attemptLogin(req: Request, res: Response, user: User): Promise<void>;
|
|
|
|
|
|
|
|
attemptRegister(req: Request, res: Response, identifier: string): Promise<void>;
|
|
|
|
}
|