forked from eunid/eunid.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirectApp.html
More file actions
104 lines (92 loc) · 4.43 KB
/
redirectApp.html
File metadata and controls
104 lines (92 loc) · 4.43 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interstitial Page</title>
</head>
<body>
<h2 id="heading">Authorization Status Unknown</h2>
<p id="errorDetail"></p>
<p>Flow finished without user interaction - Return to App via the following options</p>
<a href="index.html" id="backlink">Get me back - HTTPs</a> <br> <br>
<a href="index.html" id="backlink2">Get me back - Scheme</a> <br> <br>
<script>
//In real deployment this should be handled server-side idealy
const platform = () => {
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 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 createLinks = () => {
let os = platform();
let httpsLink = document.getElementById('backlink')
let customSchemeLink = document.getElementById('backlink2')
let errorDetail = document.getElementById('errorDetail');
let httpsURI, customSchemeURI
errorDetail.innerText = 'User-Agent: ' + os;
/*
https://developerzone.netid.dev/redirectApp will automatically redirect to the respective AppLink (Android) / Universal Link (iOS). This could also be another subdomain, but generally necessary given the browser won't trigger the Link to the App otherwise.
*/
// On Android both App Links and a Custom Scheme (with security downsides and pot. prompts) is feasible
if(os == 'Android'){
console.log(os);
httpsURI = 'https://developerzone.netid.dev/redirectApp' + document.location.search
customSchemeURI = 'de.netid.sdk://redirect/redirectApp' + document.location.search
// On iOS Universal Link is feasible.
}else if (os == 'iOS'){
console.log(os);
httpsURI = 'https://developerzone.netid.dev/redirectApp' + document.location.search
//hide second option
customSchemeLink.style.display = 'none'
// Just for testing porposes (Desktop etc.)
} else {
console.log(os);
httpsURI = 'https://developerzone.netid.dev/redirectApp' + document.location.search
customSchemeURI = 'de.netid.sdk://redirect/redirectApp' + document.location.search
}
console.log(httpsURI)
console.log(customSchemeURI)
httpsLink.setAttribute('href',httpsURI)
customSchemeLink.setAttribute('href',customSchemeURI)
};
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
}
let error = getError();
let success = checkSuccess();
let heading = document.getElementById('heading');
let errorDetail = document.getElementById('errorDetail');
//create options to return to app
createLinks();
//Flow repsonded with an error
if(error != null){
//do something meaningfull (i.e. change page) - mock
heading.textContent = 'Authorization Error'
errorDetail.innerHTML = error + ' | ' + errorDetail.innerHTML
} else if (success) {
//do something meaningfull (i.e. change page) - mock
heading.textContent = 'Authorization SuccessFull'
//errorDetail.innerHTML = error
} // leave unknown instead (site simply opened witouth parameters)
</script>
</body>
</html>