Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
// There is no valid token.
if (!scopes) {
response.statusCode = 401;
meta.message =
"Restricting access." + (warning ? ` (${warning})` : "");
meta.rule = rule;
meta.behavior = behavior;
send();
return;
}
// The token is valid, but lacks required scopes.
if (
!isEqual(scopes, behavior.requireScopes) &&
!isSuperset(scopes, behavior.requireScopes)
) {
response.statusCode = 403;
meta.message =
"Restricting access." + (warning ? ` (${warning})` : "");
meta.rule = rule;
meta.behavior = behavior;
send();
return;
}
}
// Strip the token from the proxied request.
if (!behavior.sendTokenToTarget || !scopes) {
delete request.headers.authorization;
}
const possibleRequestedAuthorizations = authorizations.filter(t =>
isEqual(
inject(requestedScopeTemplates, {
/* eslint-disable @typescript-eslint/camelcase */
current_user_id: grant.userId ?? null,
current_grant_id: grant.id ?? null,
current_client_id: grant.clientId ?? null,
current_authorization_id: t.id ?? null
/* eslint-enable @typescript-eslint/camelcase */
}),
t.scopes
)
);
const possibleRequestedAuthorizations = authorizations.filter(t =>
isEqual(requestedScopes, t.scopes)
);
const possibleRootAuthorizations = authorizations.filter(t =>
isEqual("**:**:**", t.scopes)
);