mirror of
https://github.com/nodejs/node.git
synced 2025-05-16 00:11:20 +00:00

PR-URL: https://github.com/nodejs/node/pull/43917 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
21 lines
558 B
JavaScript
21 lines
558 B
JavaScript
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
|