packages/cozy-jobs-cli/src/cozy-authenticate.js
function onRegistered(client, url) {
  let server
  return new Promise(resolve => {
    server = http.createServer((request, response) => {
      if (request.url.indexOf('/do_access') === 0) {
        log('debug', request.url, 'url received')
        resolve(request.url)
        response.end(
          'Authorization registered, you can close this page and go back to the cli'
        )
      }
    })
    server.listen(3333, () => {
      require('opn')(url, { wait: false })
      console.log(
        'A new tab just opened in your browser to require the right authorizations for this connector in your cozy. Waiting for it...'
      )
      console.log(
        'If your browser does not open (maybe your are in a headless virtual machine...), then paste this url in your browser'
      )
      console.log(url)
    })
  }).then(
    url => {
      server.close()
      return url
    },
    err => {
      server.close()
      log('error', err, 'registration error')
      throw err
    }
  )
}
function onRegistered(client, url) {
  let server
  return new Promise(resolve => {
    server = http.createServer((request, response) => {
      if (request.url.indexOf('/do_access') === 0) {
        log('debug', request.url, 'url received')
        resolve(request.url)
        response.end(
          'Authorization registered, you can close this page and go back to the cli'
        )
      }
    })
    server.listen(3333, () => {
      require('opn')(url, { wait: false })
      console.log(
        'A new tab just opened in your browser to require the right authorizations for this connector in your cozy. Waiting for it...'
      )
      console.log(
        'If your browser does not open (maybe your are in a headless virtual machine...), then paste this url in your browser'
      )
      console.log(url)
    })
  }).then(
    url => {
      server.close()
      return url
    },
    err => {
      server.close()
      log('error', err, 'registration error')
      throw err
    }
  )
}
function onRegistered ( client , url ) { let server return new Promise ( resolve => { server = http . createServer ( ( request , response ) => { if ( request . url . indexOf ( '/do_access' ) === 0 ) { log ( 'debug' , request . url , 'url received' ) resolve ( request . url ) response . end ( 'Authorization registered, you can close this page and go back to the cli' ) } } ) server . listen ( 3333 , ( ) => { require ( 'opn' ) ( url , { wait : false } ) console . log ( 'A new tab just opened in your browser to require the right authorizations for this connector in your cozy. Waiting for it...' ) console . log ( 'If your browser does not open (maybe your are in a headless virtual machine...), then paste this url in your browser' ) console . log ( url ) } ) } ) . then ( url => { server . close ( ) return url } , err => { server . close ( ) log ( 'error' , err , 'registration error' ) throw err } ) }
check if we have a token file if any return a promise with the credentials
check if we have a token file if any return a promise with the credentials