This commit is contained in:
parent
01cb121a68
commit
008fd3f545
0
lib/Authenticator.ts
Normal file
0
lib/Authenticator.ts
Normal file
37
lib/Gateway.ts
Normal file
37
lib/Gateway.ts
Normal file
@ -0,0 +1,37 @@
|
||||
type AnyFunc = (...args: unknown) => unknown;
|
||||
type Gateway = (req: Request, res: Response, next: AnyFunc) => Promise<void>;
|
||||
|
||||
interface GatewayOptions {
|
||||
redirect_url: string;
|
||||
use_stored_sessions?: boolean;
|
||||
}
|
||||
|
||||
class GatewayClass {
|
||||
private options: GatewayOptions;
|
||||
|
||||
public constructor (options: GatewayOptions) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
private redirect (res): void {
|
||||
res.statusCode = 302;
|
||||
res.setHeader ('Location', this.options.redirect_url);
|
||||
res.end ();
|
||||
}
|
||||
|
||||
private async authenticate (req): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public async process_request (req: Request, res: Response, next: AnyFunc): Promise<void> {
|
||||
if (await this.authenticate (req))
|
||||
next ();
|
||||
else
|
||||
this.redirect (res);
|
||||
}
|
||||
}
|
||||
|
||||
export default function create_gateway (options: GatewayOptions): Gateway {
|
||||
const g = new GatewayClass (options);
|
||||
return g.process_request;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user