-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb2app.html
More file actions
310 lines (270 loc) · 10.6 KB
/
web2app.html
File metadata and controls
310 lines (270 loc) · 10.6 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web2App-Test-Page</title>
<style>
/* General Styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
h2 {
text-align: center;
margin-bottom: 20px;
}
/* Form Styles */
form {
background-color: #ffffff;
border-radius: 4px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 20px;
}
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 15px;
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #2c3e50;
color: #ffffff;
font-weight: bold;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s ease;
}
.form-element {
width: 100%;
box-sizing: border-box;
margin-bottom: 15px;
}
/* Add a class for success messages */
.success-message {
background-color: #dff0d8;
border: 1px solid #d6e9c6;
border-radius: 4px;
padding: 10px;
margin-bottom: 15px;
color: #3c763d;
}
/* Add a class for error messages */
.error-message {
background-color: #f2dede;
border: 1px solid #ebccd1;
border-radius: 4px;
padding: 10px;
margin-bottom: 15px;
color: #a94442;
}
.info-box {
background-color: #e0f0ff;
border: 1px solid #4c9aff;
padding: 1rem;
border-radius: 4px;
font-size: 1rem;
color: #333;
margin-bottom: 1rem;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
button:hover {
background-color: #34495e;
}
.hidden {
display: none;
}
/* Media Queries for Responsiveness */
@media screen and (max-width: 600px) {
.container {
padding: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<h2 id="heading">Web2App Test</h2>
<p id="errorDetail" class="error-message hidden"></p>
<p id="successDetail" class="success-message hidden"></p>
<div id="loginform">
<label for="email">Account:</label>
<input type="email" id="email" name="email" class="form-element">
<button id="authButton" class="form-element">Login mit netID</button>
<p id="apDetail" class="info-box hidden"></p>
</div>
<div id="loggedInForm" class="hidden">
<label for="resetButton">Status zurücksetzen:</label>
<button id="resetButton">Reset</button>
</div>
</div>
</form>
<script>
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
const hasTouchScreen = () => {
let hasTouchScreen = false;
if ("maxTouchPoints" in navigator) {
hasTouchScreen = navigator.maxTouchPoints > 0;
} else if ("msMaxTouchPoints" in navigator) {
hasTouchScreen = navigator.msMaxTouchPoints > 0;
} else {
const mQ = matchMedia?.("(pointer:coarse)");
if (mQ?.media === "(pointer:coarse)") {
hasTouchScreen = !!mQ.matches;
} else if ("orientation" in window) {
hasTouchScreen = true; // deprecated, but good fallback
} else {
// Only as a last resort, fall back to user agent sniffing
const UA = navigator.userAgent;
hasTouchScreen =
/\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
/\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
}
}
return hasTouchScreen;
};
//In real deployment this should be handled server-side idealy
const getPlatform = () => {
let userAgent = navigator.userAgent || navigator.vendor || window.opera;
console.log(userAgent);
if (/android/i.test(userAgent)) return 'Android';
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) return 'iOS';
return 'other';
};
const isFireFoxAndroid = () => {
let isFireFox = false
if (hasTouchScreen()) {
const UA = navigator.userAgent
isFireFox =
/\b(FireFox)\b/i.test(UA) &&
/\b(Android)\b/i.test(UA)
}
return isFireFox;
}
const checkSuccess = () => {
let query = document.location.search;
let params = new URLSearchParams(query);
if (params.has('state') && params.has('code')) {
console.log(params.get('Redirect with state: ' + params.get('state') + ' and code: ' + params.get('code')))
return true
}
return false
}
const getError = () => {
let query = document.location.search;
let params = new URLSearchParams(query);
if (params.has('error')) {
console.log(params.get('error'))
console.log(params.get('error_description'))
return 'Error: ' + params.get('error') + ' Description: ' + params.get('error_description')
}
return null
};
const generateAuthURI = (domain, path, email) => {
const baseURI = 'https://AUTH_DOMAIN/AUTH_PATH?redirect_uri=https%3A%2F%2Feunid.github.io%2Fweb2app&client_id=73729a4c-9523-4da3-9a40-b99f1c046952&response_type=code&state=web2app&nonce=b5zydPHsFSrBRtp0I_xTJA&scope=openid&code_challenge=sEIVnvgdeGCxy7WxqsEkLJM1V6N3LXIsCgidxAGL638&code_challenge_method=S256&claims=%7B%22userinfo%22%3A%7B%22email%22%3A%7B%22essential%22%3Atrue%7D%2C%22email_verified%22%3A%7B%22essential%22%3Atrue%7D%7D%7D';
return baseURI.replace('AUTH_DOMAIN', domain).replace('AUTH_PATH', path) + '&login_hint=' + email;
};
const createLink = () => {
const email = document.getElementById('email').value;
const getDomain = email.substring(email.indexOf('@') + 1);
const authURIs = {
'gmx.net': generateAuthURI('sso.gmx.net', 'authorize-app2app', email),
'gmx.de': generateAuthURI('sso.gmx.net', 'authorize-app2app', email),
'web.de': generateAuthURI('sso.web.de', 'authorize-app2app', email),
'default': generateAuthURI('broker.netID.de', 'authorize', email),
};
if (!isFireFoxAndroid()) {
const targetURI = authURIs[getDomain] || authURIs.default;
window.open(targetURI, '_self');
}
};
const hideErrorMessage = () => {
const errorDetail = document.getElementById('errorDetail');
errorDetail.classList.add('hidden');
};
const showErrorMessage = (message) => {
const errorDetail = document.getElementById('errorDetail');
errorDetail.textContent = message;
// toggle success - error display
errorDetail.classList.remove('hidden');
hideSuccessMessage();
};
const hideSuccessMessage = () => {
const successInfo = document.getElementById('successDetail');
successInfo.classList.add('hidden');
};
const showSuccessMessage = (message) => {
const successInfo = document.getElementById('successDetail');
successInfo.textContent = message;
successInfo.classList.remove('hidden');
hideErrorMessage();
};
function checkDeviceCompatibility() {
if (!hasTouchScreen()) {
showErrorMessage(`Demo only works on mobile devices | ${errorDetail.innerHTML}`);
return false;
} else if (isFireFoxAndroid()) {
showErrorMessage(`${errorDetail.innerHTML} | FireFox-Android Web2App disabled`);
return false;
}
return true;
}
const emailInput = document.getElementById('email');
const submitButton = document.getElementById('authButton');
emailInput.addEventListener('input', () => {
const email = emailInput.value;
const apDetail = document.getElementById('apDetail');
const getDomain = email.substring(email.indexOf('@') + 1);
if (getDomain === 'gmx.net' || getDomain === 'gmx.de') {
apDetail.classList.remove('hidden')
apDetail.textContent = 'Anmeldung mit ihrer GMX App';
} else if (getDomain === 'web.de') {
apDetail.classList.remove('hidden')
apDetail.textContent = 'Anmeldung mit ihrer WEB.DE App';
} else {
apDetail.classList.add('hidden')
}
});
authButton = document.getElementById('authButton');
authButton.addEventListener('click', (event) => {
console.log('Button Clicked')
createLink()
});
resetButton = document.getElementById('resetButton');
resetButton.addEventListener('click', (event) => {
console.log('Reset Button Clicked')
window.open('web2app.html', '_self');
});
let error = getError();
let success = checkSuccess();
let loggedInForm = document.getElementById('loggedInForm');
let loginform = document.getElementById('loginform');
if (checkDeviceCompatibility()) {
if (error) {
showErrorMessage(`${error} | ${errorDetail.innerHTML}`);
} else if (success) {
loggedInForm.classList.remove('hidden');
loginform.classList.add('hidden');
showSuccessMessage('Login Successfull');
}
}
</script>
</body>
</html>