-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth2-redirect.html
38 lines (36 loc) · 1.27 KB
/
oauth2-redirect.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
(function () {
function handleOAuthResponse() {
// Extract the hash fragment (containing access token, id token, etc.)
var params = new URLSearchParams(window.location.hash.substring(1));
console.log(params)
// Pass extracted tokens back to Swagger UI via window.opener
if (params.has('access_token')) {
if (window.opener) {
window.opener.postMessage({
access_token: params.get('access_token'),
id_token: params.get('id_token') || '',
expires_in: params.get('expires_in') || '',
token_type: params.get('token_type') || 'Bearer'
}, window.location.origin+"/index.html");
} else {
console.error("No opener window found. Cannot send OAuth tokens.");
}
}
// Close the popup window
window.close();
}
handleOAuthResponse();
})();
</script>
</body>
</html>