Skip to content

Functionality to refresh token after a set amount of time #431

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

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