• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Boom.unauthorized函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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');
    }
}));
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:8,代码来源:server-auth-verify.ts


示例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 })
      })
    },
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:49,代码来源:basic-auth-scheme.ts


示例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();
        }
开发者ID:nozzlegear,项目名称:Gearworks,代码行数:29,代码来源:sessions.ts


示例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 });
				});
			}
开发者ID:starlightslo,项目名称:hapi-ts-gulp-mvc-example,代码行数:29,代码来源:hapi-auth-local.ts


示例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();
  })
开发者ID:lambrojos,项目名称:hapi-common,代码行数:31,代码来源:http.ts


示例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: {}});
        },
开发者ID:yashodhank,项目名称:deliver-on,代码行数:32,代码来源:auth.ts


示例7:

 authenticate: (request: Request, h: ResponseToolkit) => {
     const authorization = request.headers.authorization;
     if (!authorization) {
         throw Boom.unauthorized(null, 'Custom');
     }
     return h.authenticated({ credentials: { user: 'john' } });
 }
开发者ID:dvine-multimedia,项目名称:DefinitelyTyped,代码行数:7,代码来源:server-auth-api.ts


示例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'));
	}
};
开发者ID:starlightslo,项目名称:hapi-ts-gulp-mvc-example,代码行数:8,代码来源:index.ts


示例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)
        });
    }
开发者ID:mlinuxgada,项目名称:hapi-typescript-example,代码行数:18,代码来源:user-controller.ts


示例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());
   }
 };
开发者ID:elastic,项目名称:kibana,代码行数:9,代码来源:http_service.test.ts



注:本文中的Boom.unauthorized函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Boom.wrap函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Boom.notImplemented函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap