aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.45k stars 377 forks source link

Invalid grant, cannot login from WSL #5092

Open dkozenkov opened 2 months ago

dkozenkov commented 2 months ago

Problem

I view "invalid_grant Invalid grant provided" in my browser, when I trying "Use For Free" in "Choose a sign-in option" in VSCode.

Steps to reproduce the issue

  1. Go to VSCode, install "Amazon Q"
  2. Click on "Use For Free" in "Choose a sign-in option"
  3. See error "invalid_grant Invalid grant provided" in a browser

Expected behavior

successful sign-in

System details (run AWS: About and/or Amazon Q: About)

justinmk3 commented 2 months ago

Can you provide the Amazon Q logs?

  1. In the vscode command palette, run Amazon Q: View Logs. This reveals the Output panel with Amazon Q Logs selected.
  2. Click the gear icon and choose Debug, then click it again and choose Set As Default.
  3. Perform the steps to reproduce the issue.
  4. Remove any private info from the logs.
dkozenkov commented 2 months ago

Ok, it's my Amazon Q logs:

2024-06-05 21:09:20.524 [info] Log level: info
2024-06-05 21:09:20.524 [info] Telemetry product: Amazon Q For VS Code
2024-06-05 21:09:20.687 [info] telemetry cache not found: '/home/dims/.vscode-server/data/User/globalStorage/amazonwebservices.amazon-q-vscode/telemetryCache'
2024-06-05 21:09:20.687 [info] codewhisperer: active connection changed
2024-06-05 21:09:20.687 [info] codewhisperer: connection states
    connection isValid=false,
    connection isValidCodewhispererCoreConnection=false,
    connection isExpired=false,
    secondaryAuth isExpired=false,
    connection isUndefined=true
2024-06-05 21:09:20.849 [info] Trying to register toolkit callback. Toolkit is installed, 
                        toolkit activated = false
2024-06-05 21:09:20.849 [info] initialized 'submitFeedback' command with default feedback id: Amazon Q
2024-06-05 21:09:21.960 [info] Trying to register toolkit callback. Toolkit is installed, 
                        toolkit activated = false
2024-06-05 21:09:21.960 [info] toolkitApi: Registering callbacks of toolkit api
2024-06-05 21:09:22.044 [error] command: "aws.amazonq.refreshConnectionCallback" failed without error handler: TypeError: Cannot read properties of undefined (reading 'scopes')
2024-06-05 21:09:22.054 [error] Failed i:

{}
2024-06-05 21:10:05.602 [debug] Log level: debug
2024-06-05 21:10:12.906 [debug] command: running "aws.amazonq.listCommands" with arguments: []
2024-06-05 21:10:12.906 [debug] command: running "aws.amazonq.refreshAnnotation" with arguments: [ true ]
2024-06-05 21:10:15.931 [debug] command: running "aws.amazonq.focusChat" with arguments: [ 'placeholder**', 'codewhispererQuickPick' ]
2024-06-05 21:10:16.279 [debug] Registered event handler for: onActiveConnectionModified
2024-06-05 21:10:16.280 [debug] Webview called command "refreshAuthState" with args: []
2024-06-05 21:10:16.332 [debug] Webview called command "getAuthState" with args: []
2024-06-05 21:10:16.389 [debug] Webview called command "getDefaultStartUrl" with args: []
2024-06-05 21:10:16.389 [debug] Webview called command "getRegions" with args: []
2024-06-05 21:10:16.389 [warning] AwsContext: no default region in credentials profile, falling back to us-east-1:
2024-06-05 21:10:16.390 [debug] Webview called command "fetchConnections" with args: []
2024-06-05 21:10:16.390 [debug] Webview called command "resetStoredMetricMetadata" with args: []
2024-06-05 21:10:17.898 [debug] Webview called command "storeMetricMetadata" with args: [ { credentialSourceId: 'awsId' } ]
2024-06-05 21:10:17.901 [debug] Webview called command "emitUiClick" with args: [ 'auth_builderIdOption' ]
2024-06-05 21:10:22.980 [debug] Webview called command "startBuilderIdSetup" with args: [ 'AMAZONQ' ]
2024-06-05 21:10:22.980 [debug] called startBuilderIdSetup()
2024-06-05 21:10:22.980 [info] selected AWS ID sign in
2024-06-05 21:10:22.993 [debug] SSO token cache: read failed (file not found) key: cefda009-34e8-4629-92bf-01662a520605
2024-06-05 21:10:22.993 [info] current client registration id=undefined, 
    expires at undefined, 
    key = cefda009-34e8-4629-92bf-01662a520605
2024-06-05 21:10:23.018 [debug] auth: SSO registration cache: loaded key: {"startUrl":"https://view.awsapps.com/start","region":"us-east-1","scopes":["codewhisperer:completions","codewhisperer:analysis","codewhisperer:conversations","codewhisperer:transformations","codewhisperer:taskassist"]}
2024-06-05 21:10:23.033 [debug] auth: SSO registration cache: loaded key: {"startUrl":"https://view.awsapps.com/start","region":"us-east-1","scopes":["codewhisperer:completions","codewhisperer:analysis","codewhisperer:conversations","codewhisperer:transformations","codewhisperer:taskassist"]}
2024-06-05 21:10:23.033 [debug] AuthSSOServer: Initialized new auth server.
2024-06-05 21:11:23.149 [warning] AuthSSOServer: Authentication is taking a long time
justinmk3 commented 2 months ago

2024-06-05 21:11:23.149 [warning] AuthSSOServer: Authentication is taking a long time

When you are completing the login in your web browser, does it take longer than a minute? It looks like the Identity service is not redirecting to localhost:xx endpoint which is started by Amazon Q vscode extension to receive tokens.

Are you behind a proxy? Is there anything on your machine (e.g. antivirus) that could be interfering with a vscode extension starting a local HTTP server?

Or possibly there's a bug when WSL is involved.

Edit: This looks like the root cause:

2024-06-05 21:09:22.044 [error] command: "aws.amazonq.refreshConnectionCallback" failed without error handler: TypeError: Cannot read properties of undefined (reading 'scopes')
2024-06-05 21:09:22.054 [error] Failed i:
{}

For reference, aws.amazonq.refreshConnectionCallback will be removed with https://github.com/aws/aws-toolkit-vscode/pull/5103

dkozenkov commented 2 months ago

When you are completing the login in your web browser, does it take longer than a minute?

No, it took one second

It looks like the Identity service is not redirecting to localhost:xx endpoint which is started by Amazon Q vscode extension to receive tokens. Are you behind a proxy? Is there anything on your machine (e.g. antivirus) that could be interfering with a vscode extension starting a local HTTP server?

I don't use a proxy and use a standart Windows Security.

Or possibly there's a bug when WSL is involved.

I use Google Chrome by default. This is where the problem described appears. But I started using Microsoft Edge by default and there is no problem with it - I successfully logged into Amazon Q.