otp expire handling
Browse files
app.py
CHANGED
|
@@ -10,6 +10,8 @@ import time
|
|
| 10 |
import logging
|
| 11 |
logging.getLogger('requests_oauthlib').setLevel(logging.DEBUG)
|
| 12 |
|
|
|
|
|
|
|
| 13 |
|
| 14 |
import requests
|
| 15 |
|
|
@@ -49,48 +51,54 @@ def on_navigate(state, page_name: str):
|
|
| 49 |
|
| 50 |
|
| 51 |
full = request.scheme + "://" + request.host + raw
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
print(state.authorization_url,flush = True)
|
| 57 |
-
parsed = urlparse(state.authorization_url)
|
| 58 |
-
|
| 59 |
-
# 2. Extrait les paramètres dans un dict (valeur encapsulée dans une liste)
|
| 60 |
-
params = parse_qs(parsed.query)
|
| 61 |
-
|
| 62 |
-
# 3. Récupère la valeur de state
|
| 63 |
-
state_value = params.get("state", [""])[0]
|
| 64 |
-
code = params.get("code", [""])[0]
|
| 65 |
-
print(state_value,flush = True)
|
| 66 |
-
print(state.states,flush = True)
|
| 67 |
-
print(code,flush = True)
|
| 68 |
-
if state_value.endswith('?'):
|
| 69 |
-
state_value = state_value[:-1]
|
| 70 |
else:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
|
|
@@ -106,7 +114,7 @@ def on_navigate(state, page_name: str):
|
|
| 106 |
|
| 107 |
|
| 108 |
with tgb.Page(class_name="bodyp") as callb:
|
| 109 |
-
tgb.text("
|
| 110 |
|
| 111 |
# Create pages
|
| 112 |
with tgb.Page(class_name="bodyp") as page_appart:
|
|
|
|
| 10 |
import logging
|
| 11 |
logging.getLogger('requests_oauthlib').setLevel(logging.DEBUG)
|
| 12 |
|
| 13 |
+
mssage_callback = "Wait a mement, you will be redirected"
|
| 14 |
+
|
| 15 |
|
| 16 |
import requests
|
| 17 |
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
full = request.scheme + "://" + request.host + raw
|
| 54 |
+
if "otp_expired" in full:
|
| 55 |
+
state.mssage_callback = "Your link has expired, please try again to register"
|
| 56 |
+
time.sleep(1)
|
| 57 |
+
navigate(state, "Accueil")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
else:
|
| 59 |
+
|
| 60 |
+
state.authorization_url = full
|
| 61 |
+
state.authorization_url = state.authorization_url.replace("/taipy-jsx", "")
|
| 62 |
+
state.authorization_url = state.authorization_url.rsplit("&v", 1)[0]
|
| 63 |
+
state.authorization_url = state.authorization_url.replace("http://", "https://")
|
| 64 |
+
print(state.authorization_url,flush = True)
|
| 65 |
+
parsed = urlparse(state.authorization_url)
|
| 66 |
+
|
| 67 |
+
# 2. Extrait les paramètres dans un dict (valeur encapsulée dans une liste)
|
| 68 |
+
params = parse_qs(parsed.query)
|
| 69 |
+
|
| 70 |
+
# 3. Récupère la valeur de state
|
| 71 |
+
state_value = params.get("state", [""])[0]
|
| 72 |
+
code = params.get("code", [""])[0]
|
| 73 |
+
print(state_value,flush = True)
|
| 74 |
+
print(state.states,flush = True)
|
| 75 |
+
print(code,flush = True)
|
| 76 |
+
if state_value.endswith('?'):
|
| 77 |
+
state_value = state_value[:-1]
|
| 78 |
+
else:
|
| 79 |
+
state_value = state_value
|
| 80 |
+
|
| 81 |
+
if state_value == state.states :
|
| 82 |
+
if state.Linked_social_network == "Linkedin" :
|
| 83 |
+
response = obtenir_access_token(code, state.client_id, state.client_secret, state.redirect_url)
|
| 84 |
+
|
| 85 |
+
state.token = response["access_token"]
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
url = "https://api.linkedin.com/v2/userinfo"
|
| 89 |
+
headers = {
|
| 90 |
+
"Authorization": f"Bearer {state.token}"
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
response_open = requests.get(url, headers=headers)
|
| 94 |
+
response_open =response_open.json()
|
| 95 |
+
db_manager.add_token_network(state.token,state.Linked_social_network,state.Linked_account_name,state.user_inf.user.id,response_open)
|
| 96 |
+
navigate(state,"Source_Management" )
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
print(state.token,flush = True)
|
| 100 |
+
else :
|
| 101 |
+
print("mkjgfzmfvhsmehk")
|
| 102 |
|
| 103 |
|
| 104 |
|
|
|
|
| 114 |
|
| 115 |
|
| 116 |
with tgb.Page(class_name="bodyp") as callb:
|
| 117 |
+
tgb.text("{mssage_callback}")
|
| 118 |
|
| 119 |
# Create pages
|
| 120 |
with tgb.Page(class_name="bodyp") as page_appart:
|