From a2955532cc669e2c366a1671602bd588f6dee980 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 16 Jul 2020 12:31:10 +0200 Subject: [PATCH] auth-backend: tweak error messages --- plugins/auth-backend/src/lib/OAuthProvider.test.ts | 4 ++-- plugins/auth-backend/src/lib/OAuthProvider.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/auth-backend/src/lib/OAuthProvider.test.ts b/plugins/auth-backend/src/lib/OAuthProvider.test.ts index f67a91dfcd..3d631bd4ac 100644 --- a/plugins/auth-backend/src/lib/OAuthProvider.test.ts +++ b/plugins/auth-backend/src/lib/OAuthProvider.test.ts @@ -51,7 +51,7 @@ describe('OAuthProvider Utils', () => { } as unknown) as express.Request; expect(() => { verifyNonce(mockRequest, 'providera'); - }).toThrowError('Missing nonce'); + }).toThrowError('Auth response is missing cookie nonce'); }); it('should throw error if state nonce missing', () => { @@ -63,7 +63,7 @@ describe('OAuthProvider Utils', () => { } as unknown) as express.Request; expect(() => { verifyNonce(mockRequest, 'providera'); - }).toThrowError('Missing nonce'); + }).toThrowError('Auth response is missing state nonce'); }); it('should throw error if nonce mismatch', () => { diff --git a/plugins/auth-backend/src/lib/OAuthProvider.ts b/plugins/auth-backend/src/lib/OAuthProvider.ts index 5434b6a4ba..c4996c31a2 100644 --- a/plugins/auth-backend/src/lib/OAuthProvider.ts +++ b/plugins/auth-backend/src/lib/OAuthProvider.ts @@ -43,10 +43,12 @@ export const verifyNonce = (req: express.Request, providerId: string) => { const cookieNonce = req.cookies[`${providerId}-nonce`]; const stateNonce = req.query.state; - if (!cookieNonce || !stateNonce) { - throw new Error('Missing nonce'); + if (!cookieNonce) { + throw new Error('Auth response is missing cookie nonce'); + } + if (!stateNonce) { + throw new Error('Auth response is missing state nonce'); } - if (cookieNonce !== stateNonce) { throw new Error('Invalid nonce'); } @@ -151,9 +153,8 @@ export class OAuthProvider implements AuthProviderRouteHandlers { } if (!this.options.disableRefresh) { - // throw error if missing refresh token if (!refreshToken) { - throw new Error('Missing refresh token'); + throw new InputError('Missing refresh token'); } // set new refresh token