<commit_before>OAuth.registerService('canvas',2,null,function(query) {
  //Weird hack to not reject self-signed certs in dev environment.
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
  var response = getTokenResponse(query);
  var serviceData = {
    accessToken: response.accessToken,
    expiresAt: (+new Date) + 100000
  }
  _.extend(serviceData,response.user);
  return {
    serviceData: serviceData,
    options: {profile: {name: response.user.name}}
  };
}); 

var getTokenResponse = function (query) {
  console.log(query);
  //Sends a POST request with the code we received in our GET response on the client.
  var config = ServiceConfiguration.configurations.findOne({service: 'canvas'});
  var postResponse;
  try {
    postResponse = HTTP.post(config.url + 'login/oauth2/token', {
      params: {
        client_id: config.client_id,
        redirect_uri: OAuth._redirectUri('canvas',config),
        client_secret: config.client_secret,
        state: query.state,
        code: query.code
      }
    }).data;
  } catch (err) {
    throw _.extend(new Error("Failed to complete OAuth handshake with Canvas - POST " + err.message),
                    {response: err.response});
  }


  return postResponse;
}
<commit_msg>Bugfix and removed some development testing code.<commit_after>OAuth.registerService('canvas',2,null,function(query) {
  var response = getTokenResponse(query);
  var serviceData = {
    accessToken: response.accessToken,
    expiresAt: (+new Date) + 100000
  }
  _.extend(serviceData,response.user);
  return {
    serviceData: serviceData,
    options: {profile: {name: response.user.name}}
  };
}); 

var getTokenResponse = function (query) {
  //Sends a POST request with the code we received in our GET response on the client.
  var config = ServiceConfiguration.configurations.findOne({service: 'canvas'});
  var postResponse;
  try {
    postResponse = HTTP.post(config.url + '/login/oauth2/token', {
      params: {
        client_id: config.client_id,
        redirect_uri: OAuth._redirectUri('canvas',config),
        client_secret: config.client_secret,
        state: query.state,
        code: query.code
      }
    }).data;
  } catch (err) {
    throw _.extend(new Error("Failed to complete OAuth handshake with Canvas - POST " + err.message),
                    {response: err.response});
  }


  return postResponse;
}

{'fraction_non_alphanumeric': 0.11663157894736842, 'fraction_numerical': 0.007157894736842105, 'mean_word_length': 3.288808664259928, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6490622', 'n_tokens_mistral': 727, 'n_tokens_neox': 702, 'n_words': 177}