<commit_before>if document.location.hash.indexOf("#hull-auth-status-")==0 &&  window.opener && window.opener.Hull
  try
    authCbName = document.location.hash.replace('#hull-auth-status-', '')
    cb = window.opener.__hull_login_status__
    cb(authCbName)
    return window.close()
  catch e
    console.warn("Error: " + e)

define ['jquery', 'underscore', 'lib/utils/promises', 'lib/utils/version'], ($, _, promises, version)->

  (apiFn, config, authServices=[]) ->
    # Holds the state of the authentication process
    # @type {Promise|Boolean}
    authenticating = false


    # Starts the login process
    # @throws Error with invalid providerName
    # @returns {Promise|false}
    login = (providerName, opts, callback=->)->
      return module.isAuthenticating() if module.isAuthenticating()

      throw 'The provider name must be a String' unless _.isString(providerName)
      providerName = providerName.toLowerCase()
      throw "No authentication service #{providerName} configured for the app" unless ~(authServices.indexOf(providerName + '_app'))

      authenticating = promises.deferred()
      authenticating.providerName = providerName
      authenticating.done callback if _.isFunction(callback)

      authUrl = module.authUrl(config, providerName, opts)
      module.authHelper(authUrl)

      authenticating #TODO It would be better to return the promise

    # Starts the logout process
    # @returns {Promise}
    # @TODO Misses a `dfd.fail`
    logout = (callback=->)->
      dfd = apiFn('logout')
      dfd.done ->
        callback() if _.isFunction(callback)
      dfd.promise() #TODO It would be better to return the promise

    # Callback executed on successful authentication
    onCompleteAuthentication = (isSuccess)->
      if isSuccess
        authenticating.resolve()
      else
        authenticating.reject('Login canceled')
      authenticating = false

    # Generates the complete URL to be reached to validate login
    generateAuthUrl = (config, provider, opts)->
      auth_params = opts || {}
      auth_params.app_id        = config.appId
      auth_params.callback_url  = config.callback_url || module.location.toString()
      auth_params.auth_referer  = module.location.toString()
      auth_params.callback_name = module.createCallback()
      auth_params.version       = version<commit_msg>callback_url is not javascript-y. Added callbackUrl for consistency<commit_after>if document.location.hash.indexOf("#hull-auth-status-")==0 &&  window.opener && window.opener.Hull
  try
    authCbName = document.location.hash.replace('#hull-auth-status-', '')
    cb = window.opener.__hull_login_status__
    cb(authCbName)
    return window.close()
  catch e
    console.warn("Error: " + e)

define ['jquery', 'underscore', 'lib/utils/promises', 'lib/utils/version'], ($, _, promises, version)->

  (apiFn, config, authServices=[]) ->
    # Holds the state of the authentication process
    # @type {Promise|Boolean}
    authenticating = false


    # Starts the login process
    # @throws Error with invalid providerName
    # @returns {Promise|false}
    login = (providerName, opts, callback=->)->
      return module.isAuthenticating() if module.isAuthenticating()

      throw 'The provider name must be a String' unless _.isString(providerName)
      providerName = providerName.toLowerCase()
      throw "No authentication service #{providerName} configured for the app" unless ~(authServices.indexOf(providerName + '_app'))

      authenticating = promises.deferred()
      authenticating.providerName = providerName
      authenticating.done callback if _.isFunction(callback)

      authUrl = module.authUrl(config, providerName, opts)
      module.authHelper(authUrl)

      authenticating #TODO It would be better to return the promise

    # Starts the logout process
    # @returns {Promise}
    # @TODO Misses a `dfd.fail`
    logout = (callback=->)->
      dfd = apiFn('logout')
      dfd.done ->
        callback() if _.isFunction(callback)
      dfd.promise() #TODO It would be better to return the promise

    # Callback executed on successful authentication
    onCompleteAuthentication = (isSuccess)->
      if isSuccess
        authenticating.resolve()
      else
        authenticating.reject('Login canceled')
      authenticating = false

    # Generates the complete URL to be reached to validate login
    generateAuthUrl = (config, provider, opts)->
      auth_params = opts || {}
      auth_params.app_id        = config.appId
      # The following is here for backward compatibility. Must be removed at first sight next time
      auth_params.callback_url  = config.callback_url || config.callbackUrl || module.location.toString()
      auth_params.auth_referer  = module.location.toString()
      auth_params.callback_name = module.createCallback()
      auth_params.version       = version
{'fraction_non_alphanumeric': 0.10404268417812436, 'fraction_numerical': 0.0004104247896572953, 'mean_word_length': 3.3362989323843415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3995047', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1325, 'n_words': 368}