modify meldrxapi
Browse files- utils/meldrx.py +8 -3
utils/meldrx.py
CHANGED
|
@@ -85,12 +85,13 @@ class MeldRxAPI:
|
|
| 85 |
"code_challenge": code_challenge,
|
| 86 |
"code_challenge_method": "S256"
|
| 87 |
}
|
| 88 |
-
query_string =
|
|
|
|
| 89 |
return f"{self.authorize_url}?{query_string}"
|
| 90 |
|
| 91 |
def authenticate_with_code(self, auth_code: str) -> bool:
|
| 92 |
if not self.code_verifier:
|
| 93 |
-
print("Code verifier not set. Generate an authorization URL first.")
|
| 94 |
return False
|
| 95 |
payload = {
|
| 96 |
"grant_type": "authorization_code",
|
|
@@ -102,16 +103,20 @@ class MeldRxAPI:
|
|
| 102 |
if self.client_secret:
|
| 103 |
payload["client_secret"] = self.client_secret
|
| 104 |
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
|
|
| 105 |
try:
|
| 106 |
response = self.session.post(self.token_url, data=payload, headers=headers)
|
| 107 |
response.raise_for_status()
|
| 108 |
token_data = response.json()
|
|
|
|
| 109 |
self.access_token = token_data.get("access_token")
|
| 110 |
if not self.access_token:
|
| 111 |
raise ValueError("No access token received.")
|
| 112 |
return True
|
| 113 |
except requests.RequestException as e:
|
| 114 |
-
print(f"
|
|
|
|
|
|
|
| 115 |
return False
|
| 116 |
except ValueError as e:
|
| 117 |
print(f"Authentication error: {e}")
|
|
|
|
| 85 |
"code_challenge": code_challenge,
|
| 86 |
"code_challenge_method": "S256"
|
| 87 |
}
|
| 88 |
+
query_string = "&".join(f"{k}={v}" for k, v in params.items())
|
| 89 |
+
print(f"Generated Authorization URL: {self.authorize_url}?{query_string}") # Debugging
|
| 90 |
return f"{self.authorize_url}?{query_string}"
|
| 91 |
|
| 92 |
def authenticate_with_code(self, auth_code: str) -> bool:
|
| 93 |
if not self.code_verifier:
|
| 94 |
+
print("Error: Code verifier not set. Generate an authorization URL first.")
|
| 95 |
return False
|
| 96 |
payload = {
|
| 97 |
"grant_type": "authorization_code",
|
|
|
|
| 103 |
if self.client_secret:
|
| 104 |
payload["client_secret"] = self.client_secret
|
| 105 |
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
| 106 |
+
print(f"Token Request Payload: {payload}") # Debugging
|
| 107 |
try:
|
| 108 |
response = self.session.post(self.token_url, data=payload, headers=headers)
|
| 109 |
response.raise_for_status()
|
| 110 |
token_data = response.json()
|
| 111 |
+
print(f"Token Response: {token_data}") # Debugging
|
| 112 |
self.access_token = token_data.get("access_token")
|
| 113 |
if not self.access_token:
|
| 114 |
raise ValueError("No access token received.")
|
| 115 |
return True
|
| 116 |
except requests.RequestException as e:
|
| 117 |
+
print(f"Token Request Failed: {e}")
|
| 118 |
+
print(f"Response Status: {e.response.status_code if e.response else 'No response'}")
|
| 119 |
+
print(f"Response Text: {e.response.text if e.response else 'No response'}")
|
| 120 |
return False
|
| 121 |
except ValueError as e:
|
| 122 |
print(f"Authentication error: {e}")
|