Login auf api umgestellt und Passworteingabe über URL ermöglicht
This commit is contained in:
1 parent
160dabc59d
commit
7d7e19876d
2 files changed
+84
-5
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import requests
|
||||
|
||||
def get_tonie_api_token(username: str, password: str) -> str | None:
|
||||
token_url = "https://login.tonies.com/auth/realms/tonies/protocol/openid-connect/token"
|
||||
payload = {
|
||||
"grant_type": "password",
|
||||
"client_id": "my-tonies",
|
||||
"username": username,
|
||||
"password": password,
|
||||
"scope": "openid"
|
||||
}
|
||||
headers = {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
}
|
||||
|
||||
try:
|
||||
resp = requests.post(token_url, data=payload, headers=headers, timeout=10)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
return data.get("access_token")
|
||||
else:
|
||||
print(f"Fehler bei Token-Anfrage: {resp.status_code} - {resp.text}")
|
||||
#log_to_db("FEHLER", f"Fehler bei Token-Anfrage: {resp.status_code} - {resp.text}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Exception beim Token-Abruf: {e}")
|
||||
#log_to_db("FEHLER", f"Exception beim Token-Abruf: {e}")
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_tonie_api_token(username="sandromormile@gmail.com", password="Sandro92@tonies"))
|
||||
Reference in new issue
Block a user