Snowflake-Labs / django-snowflake

MIT License
59 stars 15 forks source link

authenticator:externalbrowser issue #81

Closed grootrm closed 6 months ago

grootrm commented 6 months ago

I am unable to get the externalbrowser window to pop up indicating successful connection. When I runserver, I get DatabaseError: Failed to connect to DB: .privatelink.snowflakecomputing.com:443. Incorrect username or password was specified.

In settings.py (using dummy variables here, real ones are used in production):

DATABASES = {
    'default': {  
        'ENGINE': 'django_snowflake',
        'DATABASE': 'SANDBOX_DB',
        'SCHEMA': '<my_schema>',
        'WAREHOUSE': 'COMPUTE_WH',
        'USER': '<my_username>',
        'PASSWORD': '<my_password>',
        'ACCOUNT': '<my_account>.privatelink',
        'OPTIONS': {
            'AUTHENTICATOR': 'externalbrowser',
            'ROLE': '<my_role>'
        }
    }
}

Also tried placing 'AUTHENTICATOR': 'externalbrowser' as its own key in default, outside of OPTIONS.

relevant package versions:

django==4.1
django-snowflake==4.1b1
snowflake-connector-python==3.6.0

system: Windows 10 Enterprise version 21H2 Intel(R) Core(TM) i5-8350U CPU @ 1.70 GHz

As additional background I am able to successfully connect to snowflake using these same exact credentials when using snowflake-connector-python package only, outside of django, just running regular queries, and can also connect and update tables using the same exact credentials in Node.js. But I can't get it to work with django-snowflake. When I runserver, the expected web browser window never appears, it just indicates incorrect username or password, but I know they're correct.

My snowflake DB admin has access to what I am doing and he has advised me that he is seeing failed connections with snowflake-connector-python 3.6.0 and that it appears as though externalbrowser is not being used, that it may be attempting to access using my username and password only, which we cannot do as we're behind company enterprise agreement with snowflake and MUST use externalbrowser authentication. Since I never see the browser window appear in django, just the incorrect username or password error in the terminal, perhaps I am doing something wrong to prevent django-snowflake from recognizing the authenticator key. But I have tried all combinations, including the exact pattern as in the quickstart docs, and still no luck.

Has anyone encountered this and could anyone advise what I am doing wrong?

Thanks in advance.

timgraham commented 6 months ago

The keys in OPTIONS shouldn't be capitalized as they correspond to the parameters of snowflake.connector.connect(). Please try with 'authenticator' and 'role'.

grootrm commented 6 months ago

Oh wow thanks Tim, that solved it! You da man.

timgraham commented 6 months ago

:+1: