Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// If authentication failed
if (result.status === 'auth-failed') {
res.set('www-authenticate', 'hawk');
throw new ErrorReply({
code: 'AuthenticationFailed',
message: result.message,
details: result,
});
}
// Render the scope expression template
const scopeExpression = scopeTemplate.render(params);
// Test that we have scope intersection, and hence, is authorized
const satisfyingScopes = !scopeExpression || scopes.scopesSatisfying(result.scopes, scopeExpression);
req.hasAuthed = true;
if (!satisfyingScopes) {
const clientId = await req.clientId();
throw new ErrorReply({
code: 'InsufficientScopes',
message: [
'Client ID ' + clientId + ' does not have sufficient scopes and are missing the following scopes:',
'',
'```',
'{{unsatisfied}}',
'```',
'',
'You have the scopes:',
'',
'```',