@@ -16,7 +16,6 @@ const CookieStore = require('tough-cookie-file-store');
1616const Crypto = require ( '../models/crypto.js' ) ;
1717const GpgAuthToken = require ( '../models/gpgAuthToken.js' ) ;
1818const GpgAuthHeader = require ( '../models/gpgAuthHeader.js' ) ;
19- const i18n = require ( '../models/i18n.js' ) ;
2019const path = require ( 'path' ) ;
2120const User = require ( '../models/user.js' ) ;
2221
@@ -44,7 +43,7 @@ class GpgAuthController extends MfaController {
4443 // URLs
4544 const baseUrl = `${ this . domain . url } /auth` ;
4645 this . URL_VERIFY = `${ baseUrl } /verify.json` ;
47- this . URL_CHECKSESSION = `${ baseUrl } /checkSession .json` ;
46+ this . URL_CHECKSESSION = `${ baseUrl } /is-authenticated .json` ;
4847 this . URL_LOGIN = `${ baseUrl } /login.json` ;
4948 this . URL_LOGOUT = `${ baseUrl } /logout` ;
5049
@@ -132,12 +131,12 @@ class GpgAuthController extends MfaController {
132131
133132 async getCsrfToken ( ) {
134133 return new Promise ( ( resolve , reject ) => {
135- const domain = new URL ( this . domain . url ) . host ;
134+ const domain = new URL ( this . domain . url ) . hostname ;
136135 const path = '/' ;
137136 const key = 'csrfToken' ;
138137
139138 this . cookieStore . findCookie ( domain , path , key , ( error , cookie ) => {
140- if ( cookie === null ) {
139+ if ( ! cookie ) {
141140 reject ( ) ;
142141 } else {
143142 resolve ( cookie . value ) ;
@@ -268,21 +267,22 @@ class GpgAuthController extends MfaController {
268267 _serverResponseHealthCheck ( step , response ) {
269268 // Check if the HTTP status is OK
270269 if ( response . statusCode !== 200 ) {
271- throw new Error ( `${ i18n . __ ( 'There was a problem when trying to communicate with the server' )
272- } (HTTP Code:${ response . status } )`) ;
270+ throw new Error ( `There was a problem when trying to communicate with the server (HTTP Code:${ response . status } )` ) ;
273271 }
274272
275273 // Check if there is GPGAuth error flagged by the server
276- if ( response . headers [ 'x-gpgauth-error' ] ) {
277- throw new Error ( i18n . __ ( 'The server rejected the verification request.' ) + response . headers [ 'x-gpgauth-debug' ] ) ;
274+ if ( step !== 'logout' ) {
275+ if ( response . headers [ 'x-gpgauth-error' ] ) {
276+ throw new Error ( `The server rejected the verification request ${ response . headers [ 'x-gpgauth-debug' ] } ` ) ;
277+ }
278278 }
279279
280280 // Check if the headers are correct
281281 try {
282282 GpgAuthHeader . validateByStage ( step , response . headers ) ;
283283 } catch ( error ) {
284284 this . log ( error . message , 'verbose' ) ;
285- throw new Error ( i18n . __ ( 'The server was unable to respect the authentication protocol.' ) ) ;
285+ throw new Error ( 'The server was unable to respect the authentication protocol.' ) ;
286286 }
287287
288288 return true ;
@@ -302,11 +302,11 @@ class GpgAuthController extends MfaController {
302302 GpgAuthToken . validate ( 'token' , token ) ;
303303 } catch ( error ) {
304304 console . log ( error . message , 'verbose' ) ;
305- throw new Error ( i18n . __ ( 'Error: GPGAuth verify step failed. Maybe your user does not exist or have been deleted.' ) ) ;
305+ throw new Error ( 'Error: GPGAuth verify step failed. Maybe your user does not exist or have been deleted.' ) ;
306306 }
307307
308308 if ( ! this . token || token !== this . token ) {
309- throw new Error ( i18n . __ ( 'Error: The server was unable to identify. GPGAuth tokens do not match.' ) ) ;
309+ throw new Error ( 'Error: The server was unable to identify. GPGAuth tokens do not match.' ) ;
310310 }
311311 return response ;
312312 }
@@ -371,7 +371,7 @@ class GpgAuthController extends MfaController {
371371 body = JSON . parse ( response . body ) ;
372372 } catch ( syntaxError ) {
373373 this . log ( response . body . toString ( ) , 'verbose' ) ;
374- this . error ( `${ i18n . __ ( ' Error' ) } ${ response . statusCode } ${ i18n . __ ( ' could not parse server response.' ) } ` ) ;
374+ this . error ( `Error ${ response . statusCode } could not parse server response.` ) ;
375375 return ;
376376 }
377377 return body ;
0 commit comments