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

Commit

Permalink
fix(oauth2): add missing scopes to unauthorized error message
Browse files Browse the repository at this point in the history
  • Loading branch information
KalleV authored and kv979w committed Dec 20, 2019
1 parent fa83d85 commit a4bae08
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/providers/authentication.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
* @param {string[]} expectedScopes
*/
private validateResourceScopes(expectedScopes: string[]) {
const insufficientScopeError = 'Insufficient scope';

if (!Array.isArray(expectedScopes)) {
throw new Error(
'Parameter expectedScopes must be an array of strings representing the scopes for the endpoint(s)',
Expand All @@ -167,6 +165,11 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
if (expectedScopes.length === 0) {
return;
}

const insufficientScopeError = `Insufficient scope. Required scopes: ${expectedScopes.join(
' ',
)}`;

if (!req.user || typeof req.user.scope !== 'string') {
throw new HttpErrors.Forbidden(insufficientScopeError);
}
Expand Down

0 comments on commit a4bae08

Please sign in to comment.