Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQLConnection Active Directory Authentication #479

Closed
JarriqTheTechie opened this issue Jul 25, 2021 · 7 comments · Fixed by #482
Closed

MSSQLConnection Active Directory Authentication #479

JarriqTheTechie opened this issue Jul 25, 2021 · 7 comments · Fixed by #482
Labels
enhancement A feature that exists, works as intended but needs to be improved

Comments

@JarriqTheTechie
Copy link
Contributor

The feature will allow users to authenticate on a MSSQL server using their current windows user session. Currently there is no way to do this using the orm.

@JarriqTheTechie JarriqTheTechie added the enhancement A feature that exists, works as intended but needs to be improved label Jul 25, 2021
@josephmancuso
Copy link
Member

josephmancuso commented Jul 26, 2021

This is not an ORM function. This would be an authentication function in the framework you are using

@JarriqTheTechie
Copy link
Contributor Author

I think this is an important feature. It has to do with how one connects to the database. In some environments active directory is used to authenticate an application against the database instead of using a database username and password. This feature would be on the same level as any other database connection/configuration item.

Currently, this orm uses pyodbc for connecting to mssql. This can be enabled by simply adding Trusted_Connection=yes

pyodbc.connect('Driver={SQL Server};' 'Server=SERVER_NAME;' 'Trusted_Connection=yes;')

Notice, no username or password in the connection string. pyodbc takes care of these things behind the scene. This feature can be implemented in less than 20 lines of code and maybe touches 2 files in the orm ConnectionResolver.py & MSSQLConnection.py. If implemented correctly its a non-breaking feature.

@josephmancuso
Copy link
Member

Oh ok I see. I thought this was related to some kind of application level authentication. Can you open a PR for this?

@josephmancuso josephmancuso reopened this Jul 26, 2021
@josephmancuso
Copy link
Member

This should be done by setting a connection setting like this:

'mssql': {
        'driver': 'mssql',
        'host': os.getenv('MSSQL_DATABASE_HOST'),
        'user': os.getenv('MSSQL_DATABASE_USER'),
        'password': os.getenv('MSSQL_DATABASE_PASSWORD'),
        'database': os.getenv('MSSQL_DATABASE_DATABASE'),
        'port': os.getenv('MSSQL_DATABASE_PORT'),
        'prefix': '',
        'log_queries': True,
        'options': {
            'trusted_connection': True
       }
    },

Then inside the connection we can do something like:

f"DRIVER={mssql_driver};SERVER={self.host},{self.port};DATABASE={self.database};UID={self.user};PWD={self.password}{'Trusted_Connection=yes' if self.options.get('trusted_connection') else ''}"

@JarriqTheTechie
Copy link
Contributor Author

I’ll create the PR this weekend.

@josephmancuso
Copy link
Member

@JarriqTheTechie https://orm.masoniteproject.com/installation#mssql

@JarriqTheTechie
Copy link
Contributor Author

This is wonderful. Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature that exists, works as intended but needs to be improved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants