Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const parts = authorization.split(/\s+/);
if (parts.length !== 2) {
return h.continue; // Error without error or credentials
}
const username = parts[1];
const credentials = settings.users[username];
if (!credentials) {
throw Boom.unauthorized('Missing credentials', 'Custom');
}
if (credentials === 'skip') {
return h.unauthenticated(Boom.unauthorized(null, 'Custom'));
}
if (typeof credentials === 'string') {
return h.response(credentials).takeover();
}
credentials.user = credentials.user || null;
return h.authenticated({ credentials, artifacts: settings.artifacts });
},
response: (request, h) => {
}
) {
affected_rows
}
}
`;
let hasura_data;
try {
hasura_data = await graphql_client.request(mutation, {
user_id: user.id,
});
} catch (e) {
console.error(e);
// console.error('Error connection to GraphQL');
return next(Boom.unauthorized('Unable to delete refresh token'));
}
res.send('OK');
});
handler: function (request, h) {
if (!request.auth.isAuthenticated) {
throw Boom.unauthorized('Authentication failed: ' + request.auth.error.message);
}
// Just store the third party credentials in the session as an example. You could do something
// more useful here - like loading or setting up an account (social signup).
request.auth.session.set(request.auth.credentials);
return h.redirect('/');
}
}
async changePassword(id, { password, newPassword }, trx) {
const { Users } = this.server.models();
const foundUser = await Users.query(trx).throwIfNotFound().findById(id);
const result = await this.pwd.verify(Buffer.from(password), foundUser.password);
//Unrecognized hash is a pain/contrived to generate, don't bother
// $lab:coverage:off$
if (result === SecurePassword.INVALID ||
result === SecurePassword.INVALID_UNRECOGNIZED_HASH) {
// $lab:coverage:on$
throw Boom.unauthorized('Invalid Password');
}
return await this.setPassword(id, newPassword, trx);
}
// Set the credentials for the rest of the pipeline
// return resolve(
return h.authenticated({
credentials: {
authorizer,
context: policy.context,
principalId: policy.principalId,
usageIdentifierKey: policy.usageIdentifierKey,
},
})
} catch (err) {
serverlessLog(
`Authorization function returned an error response: (λ: ${authFunName})`,
)
return Boom.unauthorized('Unauthorized')
}
},
})
imp.verify = async (auth) => {
await Hoek.wait(1);
if (auth.credentials.user !== 'steve') {
throw Boom.unauthorized('Invalid');
}
};
handler: () => {
throw Boom.unauthorized('Original message');
},
ext: {
function tokenAuthorizationError(scopeOptions, params) {
return nock(authorizationServerUrl, scopeOptions)
.post('/oauth/token', params)
.reply(401, Boom.unauthorized(), {
'Content-Type': 'application/json',
});
}
return { authenticate: (request, h) => h.unauthenticated(Boom.unauthorized(), { credentials: { user: 'steve' } }) };
};
async authenticate (request, h) {
const { credentials, artifacts } = await this.strategy.validate(request, h)
if (credentials) {
return h.authenticated({ credentials, artifacts })
}
return h.unauthenticated(Boom.unauthorized(null, SessionScheme.name))
}
}