<commit_before>import { EventEmitter } from 'events';
import AuthenticationWindow from './authentication-window'
import Credential from '../domain/models/Credential'

class Authenticator extends EventEmitter {
  constructor(twitterApi) {
    super();
    this.twitterApi = twitterApi;
  }

  authenticateViaWindow(force) {
    this.twitterApi.getRequestToken((error, requestToken, requestTokenSecret) => {
      const authUrl = this.twitterApi.getAuthUrl(requestToken + "&force_login=" + force);
      this._extractOauthVerifierFromWindow(authUrl, (oauthVerifier) => {
        this.twitterApi.getAccessToken(requestToken, requestTokenSecret, oauthVerifier,
          (error, accessToken, accessTokenSecret, { user_id, screen_name }) => {
            const credential = new Credential(user_id, accessToken, accessTokenSecret, screen_name);
            this.emit('authentication-succeeded', credential);
          });
      });
    });

    return this;
  }

  _extractOauthVerifierFromWindow(authUrl, callback) {
    const window = new AuthenticationWindow(authUrl);

    window.onWillNavigate((authedUrl) => {
      let matched;
      if (matched = authedUrl.match(/\?oauth_token=([^&]*)&oauth_verifier=([^&]*)/)) {
        callback(matched[2]);
        setImmediate(() => {
          window.close();
        });
      } else if (matched = authedUrl.match(/&redirect_after_login_verification=([^&]*)/)) {
        window.onDidGetRedirectRequest((newUrl) => {
          this._getAccessTokenFromWindow(newUrl);
        });
      }
    });
  }

}

export default Authenticator
<commit_msg>[Bugfix] Use _extractOauthVerifierFromWindow<commit_after>import { EventEmitter } from 'events';
import AuthenticationWindow from './authentication-window'
import Credential from '../domain/models/Credential'

class Authenticator extends EventEmitter {
  constructor(twitterApi) {
    super();
    this.twitterApi = twitterApi;
  }

  authenticateViaWindow(force) {
    this.twitterApi.getRequestToken((error, requestToken, requestTokenSecret) => {
      const authUrl = this.twitterApi.getAuthUrl(requestToken + "&force_login=" + force);
      this._extractOauthVerifierFromWindow(authUrl, (oauthVerifier) => {
        this.twitterApi.getAccessToken(requestToken, requestTokenSecret, oauthVerifier,
          (error, accessToken, accessTokenSecret, { user_id, screen_name }) => {
            const credential = new Credential(user_id, accessToken, accessTokenSecret, screen_name);
            this.emit('authentication-succeeded', credential);
          });
      });
    });

    return this;
  }

  _extractOauthVerifierFromWindow(authUrl, callback) {
    const window = new AuthenticationWindow(authUrl);

    window.onWillNavigate((authedUrl) => {
      let matched;
      if (matched = authedUrl.match(/\?oauth_token=([^&]*)&oauth_verifier=([^&]*)/)) {
        callback(matched[2]);
        setImmediate(() => {
          window.close();
        });
      } else if (matched = authedUrl.match(/&redirect_after_login_verification=([^&]*)/)) {
        window.onDidGetRedirectRequest((newUrl) => {
          this._extractOauthVerifierFromWindow(newUrl);
        });
      }
    });
  }

}

export default Authenticator

{'fraction_non_alphanumeric': 0.13033988150919862, 'fraction_numerical': 0.0006236357966947302, 'mean_word_length': 3.5633001422475106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2221135', 'n_tokens_mistral': 956, 'n_tokens_neox': 927, 'n_words': 150}