This commit is contained in:
parent
c7708f4bc0
commit
80a98704af
@ -106,7 +106,7 @@ class GatewayClass {
|
||||
return result;
|
||||
}
|
||||
|
||||
public authenticate (req: IncomingMessage): boolean {
|
||||
public try_access (req: IncomingMessage): boolean {
|
||||
logger ('authenticating incoming request');
|
||||
const cookies = this.get_cookie_auth (req);
|
||||
let auth = this.get_header_auth (req);
|
||||
@ -176,22 +176,36 @@ class GatewayClass {
|
||||
return false;
|
||||
}
|
||||
|
||||
public async authenticate (
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse
|
||||
): Promise<unknown> {
|
||||
logger ('trying to authenticate http request');
|
||||
if (this.try_access (req)) {
|
||||
logger ('authenticated via access_token');
|
||||
return true;
|
||||
}
|
||||
if (await this.try_refresh (req, res)) {
|
||||
logger ('authenticated via refresh_token');
|
||||
return true;
|
||||
}
|
||||
|
||||
logger ('could not verify session');
|
||||
return false;
|
||||
}
|
||||
|
||||
public async process_request (
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
next: AnyFunc
|
||||
): Promise<unknown> {
|
||||
logger ('processing incoming http request');
|
||||
if (this.authenticate (req)) {
|
||||
if (await this.authenticate (req, res)) {
|
||||
logger ('authentification successful, calling next handler');
|
||||
return next ();
|
||||
}
|
||||
if (await this.try_refresh (req, res)) {
|
||||
logger ('refresh successful, calling next handler');
|
||||
return next ();
|
||||
}
|
||||
|
||||
logger ('could not verify session, redirecting to auth gateway');
|
||||
logger ('failed to authenticate, redirecting client');
|
||||
return this.redirect (res);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sapphirecode/auth-server-helper",
|
||||
"version": "2.2.3",
|
||||
"version": "2.2.4",
|
||||
"main": "dist/index.js",
|
||||
"author": {
|
||||
"name": "Timo Hocker",
|
||||
|
Loading…
x
Reference in New Issue
Block a user