Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
fix: throw error if forbidden
Browse files Browse the repository at this point in the history
  • Loading branch information
JamilOmar committed Nov 10, 2019
1 parent 8760141 commit fd30826
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/providers/authentication.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ParseParams,
FindRoute,
ParameterObject,
HttpErrors,
} from '@loopback/rest';
import {AuthenticateFn, AuthenticationBindings} from '../keys';
import * as jwksClient from 'jwks-rsa';
Expand Down Expand Up @@ -154,7 +155,7 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
* @param {string[]} expectedScopes
*/
private validateResourceScopes(expectedScopes: string[]) {
const error = (res: any) => res.status(403).send('Insufficient scope');
const insufficientScopeError = 'Insufficient scope';

if (!Array.isArray(expectedScopes)) {
throw new Error(
Expand All @@ -167,7 +168,7 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
return;
}
if (!req.user || typeof req.user.scope !== 'string') {
return error(res);
throw new HttpErrors.Forbidden(insufficientScopeError);
}

const replaceValue = (parsedParamsObj: ParsedParams) => (
Expand Down Expand Up @@ -212,8 +213,7 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
if (allowed) {
return;
}

error(res);
throw new HttpErrors.Forbidden(insufficientScopeError);
};
}
}

0 comments on commit fd30826

Please sign in to comment.