Created
April 30, 2024 12:00
-
-
Save goneri/78e7d3a41427b4608b6de688fadcee75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from datetime import timedelta | |
from django.utils import timezone | |
from oauth2_provider.models import AccessToken | |
from oauthlib.common import generate_token | |
def rotate_token(token_string): | |
current_token = AccessToken.objects.filter(token=token_string).first() | |
if not current_token: | |
print("No token found") | |
return | |
new_token = AccessToken.objects.create( | |
token=generate_token(), | |
user=current_token.user, | |
scope=current_token.scope, | |
expires=timezone.now() + timedelta(days=700), | |
) | |
current_token.revoke() | |
print(new_token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: