-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_auth.php
More file actions
218 lines (195 loc) · 7.21 KB
/
external_auth.php
File metadata and controls
218 lines (195 loc) · 7.21 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
61
62
63
64
65
66
67
68
69
70
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.1.1/css/all.css">
<link href="libs/alertify.min.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.gif" type="image/gif">
<script src="libs/main.js"></script>
<script src="libs/captcha_utils.php"></script>
<script src="libs/alertify.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Авторизация</title>
<script>
window.params = (new URL(document.location)).searchParams;
let solid_scopes = "auth," + window.params.get("scopes");
window.scopes = solid_scopes.split(",");
</script>
<div id="action_required" class="hidden-el overlap">
<iframe class="full-screen" id="action"></iframe>
</div>
<div class="extended-form" id="main">
<h1 class="thin-text">Авторизация</h1>
<div class="sep-line"></div>
<div class="full-width">
<h2 class="thin-text no-mrg-bottom no-padding-bottom" id="project_name"></h2>
<h2 class="thin-text no-mrg-top no-padding-top">запрашивает доступ к вашему аккаунту.</h2>
<div class="full-width align-left">
<div id="scope_container"></div>
</div>
</div>
<div class="align-left full-width">
<button class="button-primary" onclick="authenticate()">Продолжить</button>
<button class="button-secondary float-right" onclick="back()">Вернуться</button>
</div>
<br>
</div>
<script>
prepare_view();
window.fault_redirect = "home.php";
function back(){
location.href = window.fault_redirect;
}
var token_xhr = new XMLHttpRequest();
token_xhr.open('GET', 'api.php?section=UNAUTH&method=getAccessToken', true);
token_xhr.send();
token_xhr.onload = function (e) {
let access_token = JSON.parse(token_xhr.responseText);
switch (access_token.description) {
case "2faVerificationRequired":
open_login_menu();
break;
case "unfinishedReg":
open_login_menu();
break;
case "IPVerificationRequired":
open_login_menu();
break;
default:
window.token = access_token.token;
bootstrap();
break;
}
}
function open_login_menu(){
action_required.classList.remove("hidden-el");
main.classList.add("hidden-el");
document.getElementById("action").src = "index.php";
window.token_check = setInterval(checkaction, 500);
}
function checkaction(){
var check_token = new XMLHttpRequest();
check_token.open('GET', 'api.php?section=UNAUTH&method=getAccessToken', true);
check_token.send();
check_token.onload = function (e) {
let access_token = JSON.parse(check_token.responseText);
if(access_token.result == "OK" && access_token.token != null && access_token.description == undefined){
window.token = access_token.token;
bootstrap();
action_required.classList.add("hidden-el");
main.classList.remove("hidden-el");
document.getElementById("action").src = "";
clearInterval(window.token_check);
}
}
}
function bootstrap(){
if(window.token == "" || window.token == undefined){
open_login_menu();
}
else{
document.getElementById("main").style.display = "";
getProjectInfo();
prepare_scopes();
}
}
function prepare_scopes(){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'api.php?section=projects&method=getScopes', true);
xhr.setRequestHeader("Authorization", "Bearer " + window.token);
xhr.send();
xhr.onload = function (e) {
let result = JSON.parse(xhr.responseText);
if(result.result != "FAULT"){
let scope_container = document.getElementById('scope_container');
window.scopes_edited = [];
window.final_scopes = "";
window.scopes.forEach(element => {
if(result['scopes'][element] == undefined){
return;
}
if(element != ""){
window.final_scopes += "&scopes[" + element + "]";
}
window.scopes_edited[element] = "true";
let scope_id = "scope_" + element;
let child = document.createElement('b');
child.id = scope_id + "_header";
child.textContent = result['scopes'][element]['name'];
scope_container.appendChild(child);
var content = document.createElement('p');
content.id = scope_id + "_content";
content.textContent = result['scopes'][element]['description'];
content.classList.add('no-mrg-top');
child.after(content);
});
}
else{
alertify.notify("Произошла ошибка при обращении к серверам ULS. Повторите попытку позже.", 'error', 2, function(){back()});
}
}
}
function getProjectInfo(){
let project_public = window.params.get('public');
let onFault = window.params.get('onFault');
let sign = window.params.get('sign');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'api.php?section=projects&method=getProjectInfo&public=' + project_public + "&onFault=" + onFault + "&sign=" + sign, true);
xhr.setRequestHeader("Authorization", "Bearer " + window.token);
xhr.send();
xhr.onload = function (e) {
let result = JSON.parse(xhr.responseText);
if(result.result != "FAULT"){
let project_name = result.project_name;
let verified = result.verified;
if(result.fault_redirect != "MALFORMED"){
window.fault_redirect = result.fault_redirect;
}
let name_container = document.getElementById("project_name");
name_container.textContent = project_name;
name_container.title = result.project_id;
if(verified == 1){
let verification_mark = "<span class=\"verify_mark\">Verified</span>";
name_container.innerHTML = name_container.innerHTML + " " + verification_mark;
}
}
else{
alertify.notify("Произошла ошибка при авторизации! Повторите вход в необходимом сервисе!", 'error', 2, function(){back()});
}
}
}
function authenticate(){
if(window.scopes_edited['profile_management'] == 'true'){
alertify.confirm("Внимание!", "При продолжении, это приложение сможет управлять вашим аккаунтом! Не давайте это разрешение приложениям, которым вы не доверяете!",
function(){ sendrequest()},
function(){
console.log("[DEBUG] Cancelled Potentially Malicious Consent.")
}
);
}
else{
sendrequest();
}
}
function sendrequest(){
let project_public = window.params.get('public');
let scopes = window.final_scopes;
var xhr = new XMLHttpRequest();
xhr.open('GET', 'api.php?section=projects&method=login&public=' + project_public + scopes, true);
xhr.setRequestHeader("Authorization", "Bearer " + window.token);
xhr.send();
xhr.onload = function (e) {
let result = JSON.parse(xhr.responseText);
if(result.redirect != "" && result.redirect != undefined){
location.href = result.redirect;
return;
}
if(result.reason == 'RATE_LIMIT_EXCEEDED'){
window.failed_request = function(){
sendrequest();
};
callCaptcha();
return;
}
alertify.notify("Произошла ошибка при авторизации! Повторите вход в необходимом сервисе!", 'error', 2, function(){back()});
}
}
</script>