logout function
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Timo Hocker
2022-05-02 13:30:09 +02:00
parent ec08f8f04e
commit 84be087743
6 changed files with 73 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import authority from './Authority';
import { AuthRequest, AccessSettings } from './AuthHandler';
import { debug } from './debug';
import { extract_cookie, CookieSettings } from './cookie';
import blacklist from './Blacklist';
const logger = debug ('gateway');
@ -181,6 +182,27 @@ class GatewayClass {
logger ('failed to authenticate, redirecting client');
return this.redirect (res);
}
public logout (req: IncomingMessage): void {
const l = logger.extend ('logout');
l ('invalidating all submitted tokens');
const auth_strings = [
this.get_header_auth (req),
extract_cookie (this._options.cookie?.name, req.headers.cookie),
extract_cookie (this._options.refresh_cookie?.name, req.headers.cookie)
];
const tokens = auth_strings
.filter ((v) => v !== null)
.map ((v) => authority.verify (v as string))
.filter ((v) => v.valid);
l ('found %d tokens: %O', tokens.length, tokens);
for (const token of tokens)
blacklist.add_signature (token.id);
l ('complete');
}
}
export default function create_gateway (options: GatewayOptions): Gateway {