Cli: Webserver not responding - force:web:auth:login on Linux

Created on 3 Dec 2020  路  12Comments  路  Source: forcedotcom/cli

I've installed sfdx-cli using the npm package in a new machine and I can't authenticate in any org. I have been doing some research for 3 days but I could not find any solution. I really appreciate any help.

Steps To Reproduce:

  1. type sfdx force:auth:web:login -d -a myorg on terminal;
  2. Log in to the org

Expected result

  1. Open the login page to my org
  2. Redirect to localhost:1717
  3. Receive the message on terminal asking me to close the browse.

Actual result

The local webserver in localhost:1717 does not respond.

Additional information

I have checked the port 1717 is not in use before running the command.
I have tried Chrome and Firefox and even telnet but i got no respond from the local server.
I've check my ~/.sfdx folder and there is only the sfdx.log file. I've check the permissions for that folder and everything looks ok.
I've reinstalled the package and use node v10 and v14 with the same result.

This is the content of the sfdx.log file in trace level:

{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"level":10,"msg":"Setup child 'Login' logger instance","time":"2020-12-03T10:20:05.144Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"log":"Login","level":30,"msg":"Running command [Login] with flags [{\"setdefaultdevhubusername\":true,\"setalias\":\"DevHub\",\"loglevel\":\"trace\"}] and args [{}]","time":"2020-12-03T10:20:05.145Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"level":10,"msg":"Setup child 'WebOAuthServer' logger instance","time":"2020-12-03T10:20:05.147Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"level":10,"msg":"Setup child 'SfdxProjectJson' logger instance","time":"2020-12-03T10:20:05.147Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"level":10,"msg":"Setup child 'WebServer' logger instance","time":"2020-12-03T10:20:05.149Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"log":"WebServer","level":20,"msg":"Starting web server","time":"2020-12-03T10:20:05.150Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"log":"WebServer","level":20,"msg":"Nothing listening on host: localhost port: 1717 - good!","time":"2020-12-03T10:20:05.154Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"log":"WebOAuthServer","level":20,"msg":"------------","time":"2020-12-03T10:20:05.160Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"log":"WebServer","level":20,"msg":"socket connection initialized from 127.0.0.1","time":"2020-12-03T10:20:14.316Z","v":0}
{"name":"sfdx","hostname":"jesus-XPS-15-9530","pid":9412,"log":"WebServer","level":20,"msg":"socket connection initialized from 127.0.0.1","time":"2020-12-03T10:20:14.317Z","v":0}

OS and version:
Ubuntu 20.10
sfdx-cli/7.81.0 linux-x64 node-v10.23.0

bug

All 12 comments

I've updated to sfdx-cli/7.82.1-0 but the problem persist.

In order to check if there was any problem with my system, I run other apps like "npm serve" using the port 1717 and they work with no problem.

Just to clarify, in case my first message wasn't clear, after executing the sfdx comand the local server is running in the port 1717 and i can connect but i get no respond from it.

I run out of ideas so I'll start debugging the sfdx code to try to find the cause.

I've made it work with a really ugly 'hack'.

In @salesforce/core/lib/webOAuthServer.js there is this block of code

async authorizeAndSave() {
  if (!this.webServer.server)
  await this.start();
  return new Promise((resolve, reject) => {
    this.webServer.server.once('listening', () => {
      this.logger.debug(`OAuth web login service listening on port: ${this.webServer.port}`);
      this.executeOauthRequest()
        .then(async (response) => {
          ...

For some reason the event 'listening' has never capture and the executeOauthRequest never called. This is the line

this.webServer.server.once('listening', () => {

In my case, i just commented the line out and the auth process worked.

I had the same issue, downgrading to [email protected] helps

I had the same issue, downgrading to [email protected] helps

This is the solution that worked for me as well. I captured a debug log using --dev-debug from 7.76.0 and 7.82.1, and there are differences.

7.82.1

sfdx:core TRACE Setup child 'WebOAuthServer' logger instance +3ms
sfdx:core TRACE Setup child 'SfdxProjectJson' logger instance +3ms
sfdx:core TRACE Setup child 'WebServer' logger instance +4ms
sfdx:WebServer DEBUG Starting web server +0ms
sfdx:WebServer DEBUG Nothing listening on host: localhost port: 1717 - good! +6ms
sfdx:WebServer DEBUG socket connection initialized from 127.0.0.1 +24s
sfdx:WebServer DEBUG socket connection initialized from 127.0.0.1 +250ms <--- hangs here after credentials are entered

7.76.0

sfdx:AuthWebLoginCommand INFO Running command [AuthWebLoginCommand] with flags [{<redacted>}] and args [{}] +0ms
sfdx:core TRACE Setup child 'webLogin' logger instance +72ms
sfdx:webLogin DEBUG Nothing listening on host: localhost port: 1717 - good! +0ms
sfdx:webLogin DEBUG OAuth web login service listening on port: 1717 +3ms
sfdx:webLogin DEBUG socket connection initialized from 127.0.0.1 +22s
sfdx:webLogin DEBUG processing request for uri: /OauthRedirect +6ms
sfdx:webLogin DEBUG request.query.state: f08ea19a14e0 +0ms
sfdx:webLogin DEBUG request.query.code: aPrx .... +1ms
sfdx:core TRACE Setup child 'OauthRequestGet' logger instance +22s
sfdx:OauthRequestGet DEBUG Successfully obtained auth code: ...6wg== +0ms
sfdx:OauthRequestGet DEBUG oauthConfig.loginUrl: <redacted> +0ms
sfdx:OauthRequestGet DEBUG oauthConfig.clientId: PlatformCLI +0ms
sfdx:OauthRequestGet DEBUG oauthConfig.redirectUri: http://localhost:1717/OauthRedirect +1ms
sfdx:webLogin DEBUG socket connection initialized from 127.0.0.1 +241ms
sfdx:OauthRequestGet DEBUG Successfully traded the authcode for an access token. +1s
sfdx:webLogin DEBUG sending browser redirect response +1s
sfdx:OauthRequestGet DEBUG closed +12ms
sfdx:webLogin DEBUG closing server connection +6ms
sfdx:webLogin DEBUG number of connections open: 0 +3ms
Successfully authorized <redacted> with org ID <redacted>
You may now close the browser

Does anyone know when this implementation changed?

The 7.76 -> 7.77 was when we moved over to the open-source auth plugin. @mdonnalley can you look at the differences between salesforce-alm and @salesforce/plugin-auth. Maybe that will give as an ideal why it is failing for some users.

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

This issue has been linked to a new work item: W-8885108

@mdonnalley There are a number of what appear to be duplicates to this issue that started popping up after 7.77 was released. #767 #834 #839

In my situation I hadn't authorized a new sandbox org with 7.77+ until after a sandbox refresh sometime in December. This may explain the delayed issue reporting.

As mentioned in one of the other issues, using force:auth:device:login works as a workaround until this can be fixed.

A known issue has been created for this issue: Unable to authenticate when using force:web:auth:login on Linux

This is happening for me too on Windows.
Was running on 7.84. tried to downgrade to 7.76 with the command sfdx plugins:install [email protected] but it still fails.

Even though I could use auth:device to authorize a devorg, I wasn't able to authorize a sandbox in any way, because when I try to change the url with the -r flag, I get this error:

sfdx force:auth:device:login -r https://test.salesforce.com
ERROR running auth:device:login: Value is not a string

Closing this issue in favor of #890

See https://github.com/forcedotcom/cli/issues/890#issuecomment-790062421

Was this page helpful?
0 / 5 - 0 ratings