package main import ( "html/template" "log" "net/http" ) var indexTmpl = template.Must(template.New("index.html").Parse(`

Authenticate for:

Extra scopes:

Request offline access:

`)) func renderIndex(w http.ResponseWriter) { renderTemplate(w, indexTmpl, nil) } type tokenTmplData struct { IDToken string AccessToken string RefreshToken string RedirectURL string Claims string } var tokenTmpl = template.Must(template.New("token.html").Parse(`

ID Token:

{{ .IDToken }}

Access Token:

{{ .AccessToken }}

Claims:

{{ .Claims }}

{{ if .RefreshToken }}

Refresh Token:

{{ .RefreshToken }}

{{ end }} `)) func renderToken(w http.ResponseWriter, redirectURL, idToken, accessToken, refreshToken string, claims []byte) { renderTemplate(w, tokenTmpl, tokenTmplData{ IDToken: idToken, AccessToken: accessToken, RefreshToken: refreshToken, RedirectURL: redirectURL, Claims: string(claims), }) } func renderTemplate(w http.ResponseWriter, tmpl *template.Template, data interface{}) { err := tmpl.Execute(w, data) if err == nil { return } switch err := err.(type) { case *template.Error: // An ExecError guarantees that Execute has not written to the underlying reader. log.Printf("Error rendering template %s: %s", tmpl.Name(), err) // TODO(ericchiang): replace with better internal server error. http.Error(w, "Internal server error", http.StatusInternalServerError) default: // An error with the underlying write, such as the connection being // dropped. Ignore for now. } }