File: web-auth.js

package info (click to toggle)
npm 9.2.0~ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 318,988 kB
  • sloc: javascript: 167,820; sh: 194; makefile: 52; perl: 11
file content (20 lines) | stat: -rw-r--r-- 558 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const EventEmitter = require('events')
const { webAuthCheckLogin } = require('npm-profile')

async function webAuth (opener, initialUrl, doneUrl, opts) {
  const doneEmitter = new EventEmitter()

  const openPromise = opener(initialUrl, doneEmitter)
  const webAuthCheckPromise = webAuthCheckLogin(doneUrl, { ...opts, cache: false })
    .then(authResult => {
      // cancel open prompt if it's present
      doneEmitter.emit('abort')

      return authResult.token
    })

  await openPromise
  return await webAuthCheckPromise
}

module.exports = webAuth