diff --git a/cmd/eksterd/http.go b/cmd/eksterd/http.go index 69b8330..05d015d 100644 --- a/cmd/eksterd/http.go +++ b/cmd/eksterd/http.go @@ -11,11 +11,13 @@ import ( "strings" "time" - "github.com/alecthomas/template" - "github.com/garyburd/redigo/redis" "github.com/pstuifzand/ekster/pkg/indieauth" "github.com/pstuifzand/ekster/pkg/microsub" "github.com/pstuifzand/ekster/pkg/util" + + "github.com/alecthomas/template" + "github.com/garyburd/redigo/redis" + "willnorris.com/go/microformats" ) type mainHandler struct { @@ -67,6 +69,7 @@ type authPage struct { RedirectURI string State string Channels []microsub.Channel + App app } type authRequest struct { @@ -196,6 +199,49 @@ func performIndieauthCallback(r *http.Request, sess *session) (bool, *authRespon return verifyAuthCode(code, sess.RedirectURI, sess.AuthorizationEndpoint) } +type app struct { + Name string + IconURL string +} + +func getPropString(mf *microformats.Microformat, prop string) string { + if v, e := mf.Properties[prop]; e { + if len(v) > 0 { + if val, ok := v[0].(string); ok { + return val + } + } + } + + return "" +} + +func getAppInfo(clientID string) (app, error) { + var app app + clientURL, err := url.Parse(clientID) + if err != nil { + return app, err + } + resp, err := http.Get(clientID) + if err != nil { + return app, err + } + defer resp.Body.Close() + + md := microformats.Parse(resp.Body, clientURL) + + if len(md.Items) > 0 { + mf := md.Items[0] + + if mf.Type[0] == "h-x-app" || mf.Type[0] == "h-app" { + app.Name = getPropString(mf, "name") + app.IconURL = getPropString(mf, "icon") + } + } + + return app, nil +} + func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { conn := pool.Get() defer conn.Close() @@ -392,6 +438,9 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { page.State = state page.Channels, err = h.Backend.ChannelsGetList() + app, err := getAppInfo(clientID) + page.App = app + err = h.Templates.ExecuteTemplate(w, "auth.html", page) if err != nil { fmt.Fprintf(w, "ERROR: %q\n", err) diff --git a/templates/auth.html b/templates/auth.html index 6cf9d20..8f9727e 100644 --- a/templates/auth.html +++ b/templates/auth.html @@ -50,6 +50,12 @@

{{ .ClientID }}

+
+

{{ .App.Name }}

+
+
+

+