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