diff --git a/atom/browser/api/atom_api_url_request.cc b/atom/browser/api/atom_api_url_request.cc index 9a9fb2889217..42f08c8f05ed 100644 --- a/atom/browser/api/atom_api_url_request.cc +++ b/atom/browser/api/atom_api_url_request.cc @@ -305,9 +305,8 @@ void URLRequest::OnAuthenticationRequired( return; } - EmitRequestEvent( - false, "login", auth_info.get(), - base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_)); + Emit("login", auth_info.get(), + base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_)); } void URLRequest::OnResponseStarted( diff --git a/lib/browser/api/net.js b/lib/browser/api/net.js index ef76984ae69c..7fb2c61495e0 100644 --- a/lib/browser/api/net.js +++ b/lib/browser/api/net.js @@ -192,6 +192,25 @@ class ClientRequest extends EventEmitter { this.emit('response', response) }) + urlRequest.on('login', (event, authInfo, callback) => { + this.emit('login', authInfo, (username, password) => { + // If null or undefined usrename/password, force to empty string. + if (username === null || username === undefined) { + username = '' + } + if (typeof username !== 'string') { + throw new Error('username must be a string') + } + if (password === null || password === undefined) { + password = '' + } + if (typeof password !== 'string') { + throw new Error('password must be a string') + } + callback(username, password) + }) + }) + if (callback) { this.once('response', callback) }