-
Notifications
You must be signed in to change notification settings - Fork 0
/
sso.go
50 lines (46 loc) · 1.52 KB
/
sso.go
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
package internet
import (
"fmt"
"net/http"
"strings"
)
var ssoHTML = `
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
var src, origin, allowed = [%s];
function receiveMessage(event) {
if (allowed.indexOf(event.origin) < 0) { return; }
if (event.data === "remove") {
localStorage.removeItem("tempKey");
return;
}
src = event.source;
origin = event.origin;
src.postMessage(localStorage.getItem("tempKey"), origin);
}
window.addEventListener("message", receiveMessage, false);
var k = localStorage.getItem("tempKey");
window.setInterval(function () {
var _k = localStorage.getItem("tempKey");
if (_k !== k && src && origin) {
k = _k;
src.postMessage(localStorage.getItem("tempKey"), origin);
}
}, 3000);
</script>
</head>
<body></body>
</html>
`
func ssoFrameHandler(w http.ResponseWriter, r *http.Request) {
var ssoOrigins []string // TODO: extract from config directly
// ssoOrigins := config.GetSSOOrigins()
var origins string
if len(ssoOrigins) > 0 {
origins = `"` + strings.Join(ssoOrigins, `", "`) + `"`
}
res := fmt.Sprintf(ssoHTML, origins)
htmlResponse(w, res)
}