git.iko.soy/typeable/oauth2-proxy
on v6.0.0 help sign in
typeable/oauth2-proxy/templates.go
187 lines 4.5 kB history raw
1package main
3import (
4 "html/template"
5 "path"
6 "strings"
8 "github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
9)
11func loadTemplates(dir string) *template.Template {
12 if dir == "" {
13 return getTemplates()
14 }
15 logger.Printf("using custom template directory %q", dir)
16 funcMap := template.FuncMap{
17 "ToUpper": strings.ToUpper,
18 "ToLower": strings.ToLower,
19 }
20 t, err := template.New("").Funcs(funcMap).ParseFiles(path.Join(dir, "sign_in.html"), path.Join(dir, "error.html"))
21 if err != nil {
22 logger.Fatalf("failed parsing template %s", err)
23 }
24 return t
27func getTemplates() *template.Template {
28 t, err := template.New("foo").Parse(`{{define "sign_in.html"}}
29<!DOCTYPE html>
30<html lang="en" charset="utf-8">
31<head>
32 <title>Sign In</title>
33 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
34 <style>
35 body {
36 font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
37 font-size: 14px;
38 line-height: 1.42857143;
39 color: #333;
40 background: #f0f0f0;
41 }
42 .signin {
43 display:block;
44 margin:20px auto;
45 max-width:400px;
46 background: #fff;
47 border:1px solid #ccc;
48 border-radius: 10px;
49 padding: 20px;
50 }
51 .center {
52 text-align:center;
53 }
54 .btn {
55 color: #fff;
56 background-color: #428bca;
57 border: 1px solid #357ebd;
58 -webkit-border-radius: 4;
59 -moz-border-radius: 4;
60 border-radius: 4px;
61 font-size: 14px;
62 padding: 6px 12px;
63 text-decoration: none;
64 cursor: pointer;
65 }
67 .btn:hover {
68 background-color: #3071a9;
69 border-color: #285e8e;
70 text-decoration: none;
71 }
72 label {
73 display: inline-block;
74 max-width: 100%;
75 margin-bottom: 5px;
76 font-weight: 700;
77 }
78 input {
79 display: block;
80 width: 100%;
81 height: 34px;
82 padding: 6px 12px;
83 font-size: 14px;
84 line-height: 1.42857143;
85 color: #555;
86 background-color: #fff;
87 background-image: none;
88 border: 1px solid #ccc;
89 border-radius: 4px;
90 -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
91 box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
92 -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
93 -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
94 transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
95 margin:0;
96 box-sizing: border-box;
97 }
98 footer {
99 display:block;
100 font-size:10px;
101 color:#aaa;
102 text-align:center;
103 margin-bottom:10px;
104 }
105 footer a {
106 display:inline-block;
107 height:25px;
108 line-height:25px;
109 color:#aaa;
110 text-decoration:underline;
111 }
112 footer a:hover {
113 color:#aaa;
114 }
115 </style>
116</head>
117<body>
118 <div class="signin center">
119 <form method="GET" action="{{.ProxyPrefix}}/start">
120 <input type="hidden" name="rd" value="{{.Redirect}}">
121 {{ if .SignInMessage }}
122 <p>{{.SignInMessage}}</p>
123 {{ end}}
124 <button type="submit" class="btn">Sign in with {{.ProviderName}}</button><br/>
125 </form>
126 </div>
128 {{ if .CustomLogin }}
129 <div class="signin">
130 <form method="POST" action="{{.ProxyPrefix}}/sign_in">
131 <input type="hidden" name="rd" value="{{.Redirect}}">
132 <label for="username">Username:</label><input type="text" name="username" id="username" size="10"><br/>
133 <label for="password">Password:</label><input type="password" name="password" id="password" size="10"><br/>
134 <button type="submit" class="btn">Sign In</button>
135 </form>
136 </div>
137 {{ end }}
138 <script>
139 if (window.location.hash) {
140 (function() {
141 var inputs = document.getElementsByName('rd');
142 for (var i = 0; i < inputs.length; i++) {
143 // Add hash, but make sure it is only added once
144 var idx = inputs[i].value.indexOf('#');
145 if (idx >= 0) {
146 // Remove existing hash from URL
147 inputs[i].value = inputs[i].value.substr(0, idx);
148 }
149 inputs[i].value += window.location.hash;
150 }
151 })();
152 }
153 </script>
154 <footer>
155 {{ if eq .Footer "-" }}
156 {{ else if eq .Footer ""}}
157 Secured with <a href="https://github.com/oauth2-proxy/oauth2-proxy#oauth2_proxy">OAuth2 Proxy</a> version {{.Version}}
158 {{ else }}
159 {{.Footer}}
160 {{ end }}
161 </footer>
162</body>
163</html>
164{{end}}`)
165 if err != nil {
166 logger.Fatalf("failed parsing template %s", err)
167 }
169 t, err = t.Parse(`{{define "error.html"}}
170<!DOCTYPE html>
171<html lang="en" charset="utf-8">
172<head>
173 <title>{{.Title}}</title>
174 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
175</head>
176<body>
177 <h2>{{.Title}}</h2>
178 <p>{{.Message}}</p>
179 <hr>
180 <p><a href="{{.ProxyPrefix}}/sign_in">Sign In</a></p>
181</body>
182</html>{{end}}`)
183 if err != nil {
184 logger.Fatalf("failed parsing template %s", err)
185 }
186 return t