-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.go
65 lines (58 loc) · 1.54 KB
/
template.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package auth
import (
"fmt"
"html/template"
"os/exec"
"runtime"
log "github.com/sirupsen/logrus"
)
var templateBody = `
<!DOCTYPE html>
<html>
<head>
<script>
var amplifyCognitoConfig = {
region: "{{ .Region }}",
userPoolId: "{{ .UserPoolID }}",
userPoolWebClientId: "{{ .ClientID }}",
redirectSignIn: "http://localhost:{{ .ServerPort }}",
redirectSignOut: "http://localhost:{{ .ServerPort }}",
domain: "{{ .HostedUIDomain }}"
};
var socket = "ws://localhost:3001";
</script>
</head>
<body>
<h1>Login process complete, you can now close this window</h1>
<div id="app"></div>
<script src="./cognitohosteduilauncher.js"></script>
</body>
</html>`
func getPageTemplate() (*template.Template, []byte, error) {
log.Debug("Building auth template")
t := template.New("template.html")
staticContect, err := Asset("cognitohosteduilauncher.js")
if err != nil {
log.Error("Failed load cognitohosteduilauncher.js file", err.Error())
return nil, nil, err
}
t, err = t.Parse(templateBody)
if err != nil {
log.Error("Failed to parse template", err.Error())
return nil, nil, err
}
return t, staticContect, nil
}
func openBrowser(url string) error {
log.Debug("Opening browser")
switch runtime.GOOS {
case "linux":
return exec.Command("xdg-open", url).Run()
case "windows":
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Run()
case "darwin":
return exec.Command("open", url).Run()
default:
return fmt.Errorf("unsupported platform")
}
}