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