From 7084a801d796b45fa371f7f339ed8d279177a3c2 Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Wed, 19 Oct 2016 12:45:17 -0700 Subject: [PATCH] *: port oob template --- server/handlers.go | 3 +-- server/templates.go | 12 ++++++++++++ server/templates_default.go | 12 ++++++++++++ web/templates/oob.html | 11 +++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 web/templates/oob.html diff --git a/server/handlers.go b/server/handlers.go index 7c3d649d..83ef5376 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -384,8 +384,7 @@ func (s *Server) sendCodeResponse(w http.ResponseWriter, r *http.Request, authRe } if authReq.RedirectURI == redirectURIOOB { - // TODO(ericchiang): Add a proper template. - fmt.Fprintf(w, "Code: %s", code.ID) + s.templates.oob(w, code.ID) return } q.Set("code", code.ID) diff --git a/server/templates.go b/server/templates.go index 45d75c84..117d12c5 100644 --- a/server/templates.go +++ b/server/templates.go @@ -15,6 +15,7 @@ const ( tmplApproval = "approval.html" tmplLogin = "login.html" tmplPassword = "password.html" + tmplOOB = "oob.html" ) const coreOSLogoURL = "https://coreos.com/assets/images/brand/coreos-wordmark-135x40px.png" @@ -23,6 +24,7 @@ var requiredTmpls = []string{ tmplApproval, tmplLogin, tmplPassword, + tmplOOB, } // TemplateConfig describes. @@ -106,6 +108,7 @@ func loadTemplates(config TemplateConfig) (*templates, error) { loginTmpl: tmpls.Lookup(tmplLogin), approvalTmpl: tmpls.Lookup(tmplApproval), passwordTmpl: tmpls.Lookup(tmplPassword), + oobTmpl: tmpls.Lookup(tmplOOB), }, nil } @@ -120,6 +123,7 @@ type templates struct { loginTmpl *template.Template approvalTmpl *template.Template passwordTmpl *template.Template + oobTmpl *template.Template } type connectorInfo struct { @@ -175,6 +179,14 @@ func (t *templates) approval(w http.ResponseWriter, state, username, clientName renderTemplate(w, t.approvalTmpl, data) } +func (t *templates) oob(w http.ResponseWriter, code string) { + data := struct { + TemplateConfig + Code string + }{t.globalData, code} + renderTemplate(w, t.oobTmpl, data) +} + // small io.Writer utilitiy to determine if executing the template wrote to the underlying response writer. type writeRecorder struct { wrote bool diff --git a/server/templates_default.go b/server/templates_default.go index 63b5aaa9..3a3d031a 100644 --- a/server/templates_default.go +++ b/server/templates_default.go @@ -313,6 +313,18 @@ var defaultTemplates = map[string]string{ +{{ template "footer.html" . }} +`, + "oob.html": `{{ template "header.html" . }} + +
+

Login Successful

+ + Please copy this code, switch to your application and paste it there: +
+ +
+ {{ template "footer.html" . }} `, "password.html": `{{ template "header.html" . }} diff --git a/web/templates/oob.html b/web/templates/oob.html new file mode 100644 index 00000000..09c98e08 --- /dev/null +++ b/web/templates/oob.html @@ -0,0 +1,11 @@ +{{ template "header.html" . }} + +
+

Login Successful

+ + Please copy this code, switch to your application and paste it there: +
+ +
+ +{{ template "footer.html" . }}