This commit is contained in:
@ -7,27 +7,31 @@ interface GatewayOptions {
|
||||
}
|
||||
|
||||
class GatewayClass {
|
||||
private options: GatewayOptions;
|
||||
private _options: GatewayOptions;
|
||||
|
||||
public constructor (options: GatewayOptions) {
|
||||
this.options = options;
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
private redirect (res): void {
|
||||
res.statusCode = 302;
|
||||
res.setHeader ('Location', this.options.redirect_url);
|
||||
res.setHeader ('Location', this._options.redirect_url);
|
||||
res.end ();
|
||||
}
|
||||
|
||||
private async authenticate (req): Promise<boolean> {
|
||||
private async authenticate (req: Request): Promise<boolean> {
|
||||
await Promise.resolve (req.body);
|
||||
return false;
|
||||
}
|
||||
|
||||
public async process_request (req: Request, res: Response, next: AnyFunc): Promise<void> {
|
||||
public async process_request (
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: AnyFunc
|
||||
): Promise<void> {
|
||||
if (await this.authenticate (req))
|
||||
next ();
|
||||
else
|
||||
this.redirect (res);
|
||||
return next ();
|
||||
return this.redirect (res);
|
||||
}
|
||||
}
|
||||
|
||||
|
26
lib/KeyStore.ts
Normal file
26
lib/KeyStore.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { create_salt } from '@sapphirecode/crypto-helper';
|
||||
|
||||
class KeyStore {
|
||||
private _keys: Record<string, string> = {};
|
||||
|
||||
public get_key (iat: number, valid_for = 0): string {
|
||||
const key = Math.floor (iat / 60)
|
||||
.toFixed (0);
|
||||
|
||||
if (typeof this._keys[key] === 'string')
|
||||
return this._keys[key];
|
||||
|
||||
if (valid_for !== 0) {
|
||||
this._keys[key] = create_salt ();
|
||||
setTimeout (() => {
|
||||
delete this._keys[key];
|
||||
}, (valid_for + 5) * 1000);
|
||||
return this._keys[key];
|
||||
}
|
||||
|
||||
throw new Error ('key could not be found');
|
||||
}
|
||||
}
|
||||
|
||||
const ks: KeyStore = (new KeyStore);
|
||||
export default ks;
|
Reference in New Issue
Block a user