Skip to content

Conversation

@ralkan
Copy link

@ralkan ralkan commented Apr 28, 2025

With this PR you request a new token after a set amount of time. Sometimes tokens can become invalid after some time and this has been implemented to get around this issue.

In your django settings you can now import from mssql.base import BaseTokenManager and use it like so:

class MyTokenManager(BaseTokenManager):
    invalidate_seconds = 900  # 15 minutes

    def get_token(self):
        credential = identity DefaultAzureCredential(exclude_interactive_browser_credential=False)
        token = credential.get_token("https://database.windows.net/.default").token
        return token

And then in your DATABASES you do:

DATABASES = {
    'default': {
        'ENGINE': 'mssql',
        'TOKEN': MyTokenManager(),
        ...
}

@ralkan
Copy link
Author

ralkan commented Apr 28, 2025

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant