diff --git a/lib/Gateway.ts b/lib/Gateway.ts index 33c2a59..64b7ce6 100644 --- a/lib/Gateway.ts +++ b/lib/Gateway.ts @@ -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 { + 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 { 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); } } diff --git a/package.json b/package.json index 4742df5..40b77de 100644 --- a/package.json +++ b/package.json @@ -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",