Skip to content

Commit

Permalink
Merge pull request cesanta#12 from cesanta/data
Browse files Browse the repository at this point in the history
Use html/template instead of printf for auth page
  • Loading branch information
imax9000 committed Jun 5, 2015
2 parents 55759f6 + c7cea78 commit 7cac28e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions auth_server/server/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth_server/server/data/google_auth.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
function start() {
gapi.load('auth2', function() {
gapi.auth2.init({client_id: '%s'}).then(checkLogin);
gapi.auth2.init({client_id: '{{.ClientId}}'}).then(checkLogin);
});
}
</script>
Expand Down
7 changes: 6 additions & 1 deletion auth_server/server/google_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -132,6 +133,7 @@ type GoogleAuth struct {
config *GoogleAuthConfig
db *leveldb.DB
client *http.Client
tmpl *template.Template
}

func NewGoogleAuth(c *GoogleAuthConfig) (*GoogleAuth, error) {
Expand All @@ -144,6 +146,7 @@ func NewGoogleAuth(c *GoogleAuthConfig) (*GoogleAuth, error) {
config: c,
db: db,
client: &http.Client{Timeout: 10 * time.Second},
tmpl: template.Must(template.New("google_auth").Parse(string(MustAsset("data/google_auth.tmpl")))),
}, nil
}

Expand Down Expand Up @@ -173,7 +176,9 @@ func (ga *GoogleAuth) doGoogleAuth(rw http.ResponseWriter, req *http.Request) {
}

func (ga *GoogleAuth) doGoogleAuthPage(rw http.ResponseWriter, req *http.Request) {
fmt.Fprintf(rw, string(MustAsset("data/google_auth.tmpl")), ga.config.ClientId)
if err := ga.tmpl.Execute(rw, struct{ ClientId string }{ClientId: ga.config.ClientId}); err != nil {
http.Error(rw, fmt.Sprintf("Template error: %s", err), http.StatusInternalServerError)
}
}

// https://developers.google.com/identity/protocols/OAuth2WebServer#handlingtheresponse
Expand Down

0 comments on commit 7cac28e

Please sign in to comment.