-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogout.php
More file actions
60 lines (47 loc) · 2.22 KB
/
Copy pathlogout.php
File metadata and controls
60 lines (47 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>Tesla Logout</title>
<?php ?>
<script>
var teslaConnection = {'accessToken': getCookie('access'),'refreshToken': getCookie('refresh'), 'vehicle': getCookie('vehicle'), 'status': 'undefined' };
console.log("Requesting Revoke Tesla Access Token");
try {revokeTeslaToken()}
catch {console.log('Revoking token not successful')};
document.cookie = "access=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; // Access Cookie löschen
document.cookie = "refresh=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; // Refresh Cookie löschen
document.cookie = "vehicle=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; // Vehicle Cookie löschen
document.cookie = "location=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; // Location Cookie löschen
document.cookie = "destination=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; // Destination Cookie löschen
console.log("Tesla Access Cookies entfernt");
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
};
function revokeTeslaToken() {
console.log('Revoke Tesla Token: ' + teslaConnection.accessToken);
var teslaUrl = 'https://goingtesla.herokuapp.com/corsproxy.php?'
+ 'csurl=https://owner-api.teslamotors.com/oauth/revoke';
var body = JSON.stringify({
"token": teslaConnection.accessToken
});
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log('Token revoked: ' + this.responseText);
}
});
xhr.open("POST", teslaUrl);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", 'bearer ' + teslaConnection.accessToken);
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(body);
};
</script>
</head>
<body>
<p id="done">Tesla Token widerrufen.<br>Token aus Cookies gelöscht.<br>Logout erfolgreich.</p>
</body>
</html>