Skip to content

[QUESTION] Apply token-based authentication in Django 5.0.6 #414

Open
@ianrussel

Description

@ianrussel

Question
Hi, I would like to ask what is the correct configuration in DJANGO when using msal authentication

`DATABASES = {
'default': {
'ENGINE': 'mssql',
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER', None) if DB_HOST == 'localhost' else '',
'PASSWORD': os.getenv('DB_PASSWORD', None) if DB_HOST == 'localhost' else '',
'HOST': os.getenv('DB_HOST'), # Either 'localhost' or IP or domain name of the SQL Server
'PORT': os.getenv('DB_PORT'), # Default SQL Server port is 1433
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server', # Name of the ODBC driver you installed
'ConnectionPooling': 'False',
},
}
}

Apply token-based authentication only if not localhost

if DB_HOST != 'localhost':
DATABASES['default']['OPTIONS'].update({
'authentication': 'ActiveDirectoryAccessToken', # Authentication method
})
DATABASES['default']['TOKEN'] = get_sql_access_token() # Your MSAL token function
DATABASES['default']['extra_params'] = "Authentication=ActiveDirectoryAccessToken"`

Relevant Issues and Pull Requests

I always got error

(pyodbc.OperationalError) ('08001', "[08001] [Microsoft][ODBC Driver 17 for SQL Server]Invalid value specified for connection string attribute 'Authentication' (0) (SQLDriverConnect)")

regards,

Ian

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions