-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 20221217 ## Minor Changes - Potentially improved user experience by making it so Discord logins refresh without you logging in again.
- Loading branch information
Showing
10 changed files
with
108 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from datetime import timedelta | ||
import requests | ||
from allauth.socialaccount.models import SocialApp, SocialToken | ||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
|
||
THRESHOLD_HOURS = 24 | ||
URL = 'https://discord.com/api/oauth2/token' | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Refresh any discord oauth tokens that are expiring within the threshold' | ||
|
||
def handle(self, *args, **kwargs): | ||
# We only have one social app | ||
app = SocialApp.objects.first() | ||
|
||
# First, get all social tokens that expire within the threshold | ||
current_time = timezone.now() | ||
expiry_threshold = current_time + timedelta(hours=THRESHOLD_HOURS) | ||
self.stdout.write(f'Searching for tokens expiring between {current_time} and {expiry_threshold}') | ||
to_refresh = SocialToken.objects.filter(expires_at__lte=expiry_threshold, expires_at__gte=current_time) | ||
self.stdout.write(f'Found {to_refresh.count()} tokens') | ||
|
||
# Loop through refreshable tokens and make requests | ||
for token in to_refresh: | ||
refresh_data = { | ||
'grant_type': 'refresh_token', | ||
'client_id': app.client_id, | ||
'client_secret': app.secret, | ||
'refresh_token': token.token_secret, | ||
} | ||
self.stdout.write(f'Refreshing token for {token.account.user.username}') | ||
|
||
response = requests.post(URL, refresh_data) | ||
if response.status_code != 200: | ||
self.stderr.write(f'Token refresh failed: {response.content}') | ||
continue | ||
|
||
# Save the updated data for the token | ||
response_data = response.json() | ||
token.token = response_data['access_token'] | ||
token.token_secret = response_data['refresh_token'] | ||
token.expires_at = timezone.now() + timedelta(seconds=response_data['expires_in']) | ||
token.save() |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
VUE_APP_VERSION="20221102" | ||
VUE_APP_VERSION="20221217" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ Sentry.init({ | |
Vue, | ||
dsn: 'https://[email protected]/6180221', | ||
logErrors: true, | ||
release: 'savageaim@20221102', | ||
release: 'savageaim@20221217', | ||
}) | ||
|
||
new Vue({ | ||
|