denisenkom / django-sqlserver

Django backend for MSSQL server using pytds or adodb backend (moved here from https://bitbucket.org/cramm/django-sqlserver)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Supporting Windows authentication?

danchr opened this issue · comments

We have to use Windows authentication in production, but I see you removed support for using the original ADO driver in 31b1ffb. Perhaps because it was broken and tricky to actually use or test due to the dependancy on python-tdb?

It so happens I fixed it locally and got django-sqlserver up and running on Django 1.11 (which django-mssql doesn't support) with the ADO driver, only to pull and discover that you removed it.

So, my question is: Is it possible to use Windows authentication with the PyTDB driver, and if so, would you perhaps consider documenting it? If not, would you consider a patch to revive ADO support? After all, django-mssql doesn't seem all that active, and it'd be nice to use one driver everywhere.

Answering my own question, we settled on the following unholy hack:

    import functools, sys

    from sqlserver import base
    from pytds import login

    orig_gcp = base.DatabaseWrapper.get_connection_params_pytds

    @functools.wraps(orig_gcp)
    def get_connection_params_pytds(self):
        """Returns a dict of parameters suitable for get_new_connection."""
        conn_params = orig_gcp(self)

        conn_params['auth'] = login.SspiAuth(
            user_name=conn_params['user'],
            password=conn_params['password'],
            server_name=conn_params['server'],
            port=conn_params['port'],
        )
   
        return conn_params

    base.DatabaseWrapper.get_connection_params_pytds = \
        get_connection_params_pytds