当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Context.get方法代码示例

本文整理汇总了TypeScript中koa.Context.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Context.get方法的具体用法?TypeScript Context.get怎么用?TypeScript Context.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在koa.Context的用法示例。


在下文中一共展示了Context.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

export default async (ctx: Context, next: Function) => {
  const apiKey = ctx.get('X-API-Key');

  if (apiKey === config.appApiKey) {
    await next();
  } else {
    ctx.body = "Access denied. Invalid 'X-API-Key' header was supplied";
    ctx.status = 403;
  }
};
开发者ID:easygenerator,项目名称:lrs,代码行数:10,代码来源:verifyAppApiKey.ts

示例2: async

  return async (ctx: Context, next) => {
    const startTime = new Date().getTime();
    const date = new Date().toISOString();

    await next();

    const responseTime = new Date().getTime() - startTime;

    logger.info({
      date,
      status: ctx.status,
      remoteAddress: ctx.ip,
      method: ctx.method,
      url: ctx.url,
      referrer: ctx.get('Referrer'),
      userAgent: ctx.get('user-agent'),
      responseTime,
    });
  };
开发者ID:Canner,项目名称:canner,代码行数:19,代码来源:loggerMiddleware.ts

示例3: async

export default async (ctx: Context, next: Function) => {
  const header = 'X-Experience-API-Version';
  if (ctx.get(header) && ctx.get(header).substring(0, 3) === config.xApiVersion.substring(0, 3)) {
    await next();
  } else {
    ctx.body = "Invalid 'X-Experience-API-Version' header was supplied";
    ctx.status = 400;
  }
  ctx.set(header, config.xApiVersion);
};
开发者ID:easygenerator,项目名称:lrs,代码行数:10,代码来源:verifyXapiVersion.ts

示例4: async

export default async (ctx: Context, next: Function) => {
  const idToken = ctx.get('X-Id-Token');
  const entityId = ctx.get('X-Entity-Id');
  const entityType = ctx.get('X-Entity-Type');
  if (!idToken || !entityId || !entityType) {
    return reject(ctx);
  }
  try {
    const token: any = decodeJWT(idToken);
    const issuer = token.iss;
    const identityId = token.unique_name;
    if (!isKnownIssuer(issuer)) {
      return reject(ctx);
    }
    let path = config.permissionsEndpoint.coursePath;
    let data: any = { courseId: entityId };
    if (entityType === constants.entityTypes.learningPath) {
      path = config.permissionsEndpoint.learningPathPath;
      data = { learningpathId: entityId };
    }
    let response;
    if (issuer === 'localhost') {
      response = { body: { data: constants.accessTypes.academy } };
    } else {
      response = await httpRequestSender.post(`https://${issuer}${path}`, data, {
        Authorization: `Bearer ${idToken}`
      });
      if (!response || !response.body || response.statusCode !== 200) {
        return reject(ctx);
      }
    }
    ctx.entityId = entityId;
    ctx.entityType = entityType;
    ctx.identityId = identityId;
    ctx.identityAccessLevel = response.body.data;
  } catch (e) {
    return reject(ctx);
  }
  await next();
};
开发者ID:easygenerator,项目名称:lrs,代码行数:40,代码来源:idTokenAuth.ts

示例5: async

export default async (ctx: Context, next: Function) => {
  const accessToken = ctx.get('X-Access-Token');
  if (accessToken) {
    const info = await httpRequestSender.get(`https://${config.tokensUri}/${accessToken}`, {
      'X-Api-Key': config.tokensApiKey
    });

    if (!info || info.revoked || !info.entityId || !info.entityType || info.scopes.indexOf('read') === -1 || !info.createdBy) {
      return reject(ctx);
    }

    ctx.entityId = info.entityId;
    ctx.entityType = info.entityType;
    ctx.identityId = info.createdBy;
    await next();
    return;
  }

  await idTokenAuth(ctx, next);
};
开发者ID:easygenerator,项目名称:lrs,代码行数:20,代码来源:auth.ts


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