{"size": 799, "ext": "js", "max_stars_repo_path": "captions_please_webhook/respond_to_crc_token.js", "max_stars_repo_name": "AnilRedshift/captions_please_azure", "max_stars_repo_stars_event_min_datetime": "2020-11-15T05:26:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-15T05:26:39.000Z", "max_issues_repo_path": "captions_please_webhook/respond_to_crc_token.js", "max_issues_repo_name": "AnilRedshift/captions_please_azure", "max_issues_repo_issues_event_min_datetime": "2020-12-31T01:14:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-31T01:14:26.000Z", "max_forks_repo_path": "captions_please_webhook/respond_to_crc_token.js", "max_forks_repo_name": "AnilRedshift/captions_please_azure", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 24.96875, "max_line_length": 66, "alphanum_fraction": 0.5607008761}
const crypto = require('crypto');
const { get_secret } = require('../shared/secrets');

module.exports = async (context, req) => {
  const crc_token = req.query.crc_token;
  if (crc_token) {
    const { value: consumer_secret } = await get_secret(
      'TwitterConsumerSecret'
    );
    if (consumer_secret) {
      const hmac = crypto
        .createHmac('sha256', consumer_secret)
        .update(crc_token)
        .digest('base64');
      context.res = {
        status: 200,
        body: { response_token: `sha256=${hmac}` },
      };
    } else {
      context.res = {
        status: 500,
        body: { message: 'Missing Consumer Secret' },
      };
    }
  } else {
    context.res = {
      status: 400,
      body: { message: 'Error: crc_token missing from request.' },
    };
  }
};
