text: Github = {};
  
  OAuth.registerService('okta', 2, null, function(query) {
  
    var accessToken = getAccessToken(query);
    var identity = getIdentity(accessToken);
    var emails = getEmails(accessToken);
    var primaryEmail = _.findWhere(emails, {primary: true});
  
    return {
      serviceData: {
        id: identity.id,
        accessToken: OAuth.sealSecret(accessToken),
        email: identity.login || (primaryEmail && primaryEmail.email) || '',
        username: identity.login,
        emails: emails
      },
      options: {profile: {name: identity.name}}
    };
  });
  
  // http://developer.github.com/v3/#user-agent-required
  var userAgent = "Meteor";
  if (Meteor.release)
    userAgent += "/" + Meteor.release;
  
  var getAccessToken = function (query) {
    var config = ServiceConfiguration.configurations.findOne({service: 'okta'});
    if (!config)
      throw new ServiceConfiguration.ConfigError();
  
    var response;
    try {
      response = HTTP.post(
        "https://vanbeektech.okta.com/oauth2/v1/token", {
          headers: {
            Accept: 'application/json',
            "User-Agent": userAgent
          },
          params: {
            code: query.code,
            client_id: config.clientId,
            client_secret: OAuth.openSecret(config.secret),
            redirect_uri: "http://localhost:3000",
            state: query.state
          }
        });
    } catch (err) {
      throw _.extend(new Error("Failed to complete OAuth handshake with Github. " + err.message),
                     {response: err.response});
    }
    if (response.data.error) { // if the http response was a json object with an error attribute
      throw new Error("Failed to complete OAuth handshake with GitHub. " + response.data.error);
    } else {
      return response.data.access_token;
    }
  };
  
  var getIdentity = function (accessToken) {
    try {
      return HTTP.get(
        "https://vanbeektech.okta.com/oauth2/v1/userinfo", {
          headers: {"User-Agent": userAgent}, // http://developer.github.com/v3/#user-agent-required
          params: {access_token: accessToken}
        }).data;
    } catch (err) {
      throw _.extend(new Error("Failed to fetch identity from Github. " + err.message),
                     {response: err.response});
    }
  };
  
  var getEmails = function (accessToken) {
    try {
      return HTTP.get(
        "https://api.github.com/user/emails", {
          headers: {"User-Agent": userAgent}, // http://developer.github.com/v3/#user-agent-required
          params: {access_token: accessToken}
        }).data;
    } catch (err) {
      return [];
    }
  };
  
  Github.retrieveCredential = function(credentialToken, credentialSecret) {
    return OAuth.retrieveCredential(credentialToken, credentialSecret);
  };