Snowflake-Labs / sqltools-snowflake-driver

A Snowflake driver for the SQLTools VSCode extension.
MIT License
36 stars 16 forks source link

Snowflake Driver for SQL tools #56

Open praneeth1987 opened 2 years ago

praneeth1987 commented 2 years ago

I have installed this driver and using this in VS Code, But just want to know in which it was developed? .NET or node.js

koszti commented 2 years ago

nodejs

praneeth1987 commented 2 years ago

Thanks. Post SSO authentication in browser, I am getting below webpage pointing to local host? Is this expected and if so, how to avoid this?

Note: Authentication is working as expected just curious about the screenshot provided below

VSS Driver

xendren commented 2 years ago

We are getting the same thing. We are using the extension on a remote server using the VS Code remote SSH extension. It appears that the port for localhost is not able to return the snowflake token back to the external server. Just a guess.

xendren commented 2 years ago

The problem appears to be that the port the extension is using to open the external browser is different each time you attempt to connect, and the extension is not configuring the port as a "Forward Port" in VS Code. Once the browser hits Snowflake and logs the user in, it is attempting to send the token to localhost on the port, but it isn't being tunneled back to the remote server.

We are also using the dbt vs code extension. By calling "dbt debug", it does the same thing through the Snowflake driver and opens the external browser. Once we authenticate, it tries to return the token, but gets the same error. We were able to copy the port from the external browser, switch over to VS Code on the "Port Forwarding" tab in the terminal, click "Add Port" and paste that port number. Go back to the external browser and click the refresh button to make it try again, and it successfully captures the token since the dbt debug command is still actively listening in the terminal. We were not able to get that workaround to work when configuring a SQL Tools connection to snowflake, however.

koszti commented 2 years ago

@xendren I think your explanation makes sense.

The browser based authentication logic is implemented by the auth_web.js in the official upstream Snowflake node.js driver. It's creating a temporary "HTTP-like" server on localhost using a random port where the browser will be redirected after a successful authentication.

I think the reason why the dbt vscode extension works differently is the fact that the dbt extension is not not connecting directly to snowflake but it's using the dbt CLI under the hood. The dbt CLI is written in python, and using the more advanced python snowflake connector. I assume the python snowflake driver is implemented slightly differently than the node.js driver or it behaves differently as you're connecting to snowflake out of vs code. I haven't checked it in details though.

Just to confirm, do I understand correctly that the browser based authentication basically works, the token is somehow received via the generated URL and able to connect to snowflake? Even if the success confirmation message is not displayed in the browser. @praneeth1987 is this what you can see?

xendren commented 2 years ago

@xendren I think your explanation makes sense.

The browser based authentication logic is implemented by the auth_web.js in the official upstream Snowflake node.js driver. It's creating a temporary "HTTP-like" server on localhost using a random port where the browser will be redirected after a successful authentication.

I think the reason why the dbt vscode extension works differently is the fact that the dbt extension is not not connecting directly to snowflake but it's using the dbt CLI under the hood. The dbt CLI is written in python, and using the more advanced python snowflake connector. I assume the python snowflake driver is implemented slightly differently than the node.js driver or it behaves differently as you're connecting to snowflake out of vs code. I haven't checked it in details though.

Just to confirm, do I understand correctly that the browser based authentication basically works, the token is somehow received via the generated URL and able to connect to snowflake? Even if the success confirmation message is not displayed in the browser. @praneeth1987 is this what you can see?

Not sure if this was directed at me, but yes it will work, but the user has to determine the random port from the URL and then manually add the Port forwarding in VS Code for that port to get it to work. Every day when they reconnect to the remote server, they have to do this process.