From 42f8028591c99dcfed3ea028e811b4ddf1de04ec Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 29 Aug 2024 22:21:01 -0400 Subject: [PATCH] fix oauth callback endpoint --- website/oauth/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/website/oauth/views.py b/website/oauth/views.py index bbacab894ce..afc5b66bceb 100644 --- a/website/oauth/views.py +++ b/website/oauth/views.py @@ -48,12 +48,15 @@ def oauth_connect(service_name, auth): @must_be_logged_in def oauth_callback(service_name, auth): + provider = get_service(service_name) if flag_is_active(request, features.ENABLE_GV): - _forward_to_addon_service() + if provider._oauth_version == 1: + _forward_to_addon_service('oauth1') + elif provider._oauth_version == 2: + _forward_to_addon_service('oauth2') return {} user = auth.user - provider = get_service(service_name) # Retrieve permanent credentials from provider if not provider.auth_callback(user=user): @@ -67,12 +70,12 @@ def oauth_callback(service_name, auth): return {} -def _forward_to_addon_service(): +def _forward_to_addon_service(oauth_version): code = request.args.get('code') state = request.args.get('state') query_params = { 'code': code, 'state': state, } - gv_url = urlunparse(urlparse(GRAVYVALET_URL)._replace(path='/v1/oauth/callback', query=urlencode(query_params))) + gv_url = urlunparse(urlparse(GRAVYVALET_URL)._replace(path=f'/v1/{oauth_version}/callback', query=urlencode(query_params))) requests.get(gv_url)