本文整理汇总了TypeScript中Boom.unauthorized函数的典型用法代码示例。如果您正苦于以下问题:TypeScript unauthorized函数的具体用法?TypeScript unauthorized怎么用?TypeScript unauthorized使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unauthorized函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: authenticate
server.auth.scheme('custom', () => ({
authenticate() {
throw Boom.unauthorized(null, 'hurr');
},
async verify(_auth: RequestAuth) {
throw Boom.unauthorized(null, 'durr');
}
}));
示例2: reply
authenticate: (request: Request, reply: IReply) => {
const req = request.raw.req
const authorization = req.headers.authorization
if (!authorization) {
return reply(Boom.unauthorized('Credentials required', 'Basic', { realm }))
}
const parts = authorization.split(/\s+/)
if (parts[0].toLowerCase() !== 'basic') {
return reply(Boom.unauthorized('Credentials required', 'Basic', { realm }))
}
if (parts.length !== 2) {
return reply(Boom.badRequest('Bad HTTP authentication header format'))
}
const credentialsPart = Buffer.from(parts[1], 'base64').toString()
const sep = credentialsPart.indexOf(':')
if (sep === -1) {
return reply(Boom.badRequest('Bad header internal syntax'))
}
const username = credentialsPart.slice(0, sep)
if (!username && !allowEmptyUsername) {
return reply(Boom.unauthorized('HTTP authentication header missing username', 'Basic', { realm }))
}
const password = credentialsPart.slice(sep + 1)
validateFunc(request, username, password, (err, isValid, credentials) => {
credentials = credentials || null
if (err) {
return reply(err, null, { credentials: credentials })
}
if (!isValid) {
return reply(Boom.unauthorized('Bad username or password', 'Basic', { realm }))
}
if (!credentials || typeof credentials !== 'object') {
return reply(Boom.badImplementation('Bad credentials object received for Basic auth validation'))
}
return reply.continue({ credentials: credentials })
})
},
示例3: function
handler: async function (req, res, next) {
const model: Requests.CreateSession = req.validatedBody;
let user: User;
try {
user = await UserDb.get(model.username.toLowerCase());
} catch (e) {
const err: boom.BoomError = e;
if (err.isBoom && err.output.statusCode !== 404) {
return next(e);
}
}
if (!user || !compareSync(model.password, user.hashed_password)) {
return next(boom.unauthorized("No user found with that username or password combination."));
}
// The user has logged in again, so we'll remove their user id from the auth-invalidation cache.
try {
await Cache.deleteValue(CACHE_SEGMENT_AUTH, user._id);
} catch (e) {
inspect(`Failed to remove user ${user._id} from auth-invalidation cache.`, e);
}
res = await res.withSessionToken(user);
return next();
}
示例4: function
const validate = function() {
// Check session
const session = request.yar.get(settings.session);
if (!session) {
return reply(Boom.unauthorized(null, 'session'));
}
if (!settings.validateFunc) {
if (settings.keepAlive) {
request.yar.set(settings.session, session);
}
return reply.continue({ credentials: session, artifacts: session });
}
settings.validateFunc(request, session, (err, isValid, userData) => {
if (err || !isValid) {
if (settings.clearInvalid) {
request.yar.clear(settings.session);
}
return reply(Boom.unauthorized('Invalid session'), { credentials: userData || session, artifacts: session });
}
if (settings.keepAlive) {
request.yar.set(settings.session, session);
}
return reply.continue({ credentials: userData || session, artifacts: session });
});
}
示例5: reply
server.ext('onPreResponse', (request, reply) => {
const res = request.response;
if (res.isBoom) {
const output = res['output']
if (output.statusCode === 400) {
if (!output.payload.errorCode){
const e = Boom.badRequest(res['output'].payload.message)
e.output.payload['errorCode'] = 'ERR_VALIDATION'
return reply(e)
}
}
if (output.statusCode === 401 && output.headers['WWW-Authenticate'] === 'Token') {
request.log(['error', 'authentication'], output.payload.message || output.payload.error, output)
if (!output.payload.errorCode){
const e = Boom.unauthorized(output.payload.message)
e.output.payload['errorCode'] = 'ERR_INVALID_JWT'
return reply(e)
}
}
request.log(['error'], output.payload.message || output.payload.error, output)
return reply.continue()
}
return reply.continue();
})
示例6: async
authenticate: async (request, reply) =>
{
let body: string;
let isAuthentic: boolean;
try
{
body = await getRawBody(request);
}
catch (e)
{
return boom.wrap(e);
}
try
{
isAuthentic = await isAuthenticWebhook(request.headers["x-shopify-hmac-sha256"], body, ShopifySecretKey);
}
catch (e)
{
console.log("Failed to get isAuthentic result", e);
return reply(boom.badRequest("Failed to get isAuthentic result.", e));
}
if (!isAuthentic)
{
return reply(boom.unauthorized("Request did not pass validation."));
}
return reply.continue({credentials: {}});
},
示例7:
authenticate: (request: Request, h: ResponseToolkit) => {
const authorization = request.headers.authorization;
if (!authorization) {
throw Boom.unauthorized(null, 'Custom');
}
return h.authenticated({ credentials: { user: 'john' } });
}
示例8: function
exports.admin = function(request, reply) {
console.log(request.auth);
if (request.auth.isAuthenticated) {
reply(request.auth.credentials);
} else {
reply(Boom.unauthorized('Invalid session'));
}
};
示例9: loginUser
public async loginUser(request: Hapi.Request, reply: Hapi.ReplyNoContinue) {
const email = request.payload.email;
const password = request.payload.password;
let user: IUser = await this.database.userModel.findOne({ email: email });
if (!user) {
return reply(Boom.unauthorized("User does not exists."));
}
if (!user.validatePassword(password)) {
return reply(Boom.unauthorized("Password is invalid."));
}
reply({
token: this.generateToken(user)
});
}
示例10: async
const authenticate: AuthenticationHandler<Storage> = async (req, sessionStorage, t) => {
if (req.headers.authorization) {
const user = { id: '42' };
sessionStorage.set({ value: user, expires: Date.now() + sessionDurationMs });
return t.authenticated({ credentials: user });
} else {
return t.rejected(Boom.unauthorized());
}
};