Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVilém Duha <vilda.novak@gmail.com>2019-07-26 13:01:43 +0300
committerVilém Duha <vilda.novak@gmail.com>2019-07-26 13:51:28 +0300
commit92830c7e43ae5f701b47bcd07199ca3a7e489377 (patch)
treed8ce3558b9f9d529b89c42b61e2db0a61c53a514 /blenderkit/bkit_oauth.py
parent7ecccf12b8ff140d331ef3d45842f8bb0759e03e (diff)
BlenderKit: fix oauth failing on some connections. This updates the oauth script to last version, and also ensures the login attempt can be properly canceled when it hangs.
Diffstat (limited to 'blenderkit/bkit_oauth.py')
-rw-r--r--blenderkit/bkit_oauth.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/blenderkit/bkit_oauth.py b/blenderkit/bkit_oauth.py
index 0dc23a9c..cb0e7586 100644
--- a/blenderkit/bkit_oauth.py
+++ b/blenderkit/bkit_oauth.py
@@ -32,6 +32,8 @@ else:
import bpy
import threading
+import requests
+
from bpy.props import (
BoolProperty,
@@ -40,16 +42,20 @@ from bpy.props import (
CLIENT_ID = "IdFRwa3SGA8eMpzhRVFMg5Ts8sPK93xBjif93x0F"
PORTS = [62485, 65425, 55428, 49452]
+active_authenticator = None
def login_thread(signup=False):
+ global active_authenticator
r_url = paths.get_oauth_landing_url()
url = paths.get_bkit_url()
- thread = threading.Thread(target=login, args=([signup, url, r_url]), daemon=True)
+ authenticator = oauth.SimpleOAuthAuthenticator(server_url=url, client_id=CLIENT_ID, ports=PORTS)
+ #we store authenticator globally to be able to ping the server if connection fails.
+ active_authenticator = authenticator
+ thread = threading.Thread(target=login, args=([signup, url, r_url, authenticator]), daemon=True)
thread.start()
-def login(signup, url, r_url):
- authenticator = oauth.SimpleOAuthAuthenticator(server_url=url, client_id=CLIENT_ID, ports=PORTS)
+def login(signup, url, r_url, authenticator):
auth_token, refresh_token = authenticator.get_new_token(register=signup, redirect_url=r_url)
utils.p('tokens retrieved')
tasks_queue.add_task((write_tokens, (auth_token, refresh_token)))
@@ -140,8 +146,16 @@ class CancelLoginOnline(bpy.types.Operator):
return True
def execute(self, context):
+ global active_authenticator
preferences = bpy.context.preferences.addons['blenderkit'].preferences
preferences.login_attempt = False
+ try:
+ if active_authenticator is not None:
+ requests.get(active_authenticator.redirect_uri)
+ active_authenticator = None
+ except Exception as e:
+ print('stopped login attempt')
+ print(e)
return {'FINISHED'}