Show app info when logging in
This commit is contained in:
parent
09d2a72b33
commit
de9e27cac4
|
@ -11,11 +11,13 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alecthomas/template"
|
|
||||||
"github.com/garyburd/redigo/redis"
|
|
||||||
"github.com/pstuifzand/ekster/pkg/indieauth"
|
"github.com/pstuifzand/ekster/pkg/indieauth"
|
||||||
"github.com/pstuifzand/ekster/pkg/microsub"
|
"github.com/pstuifzand/ekster/pkg/microsub"
|
||||||
"github.com/pstuifzand/ekster/pkg/util"
|
"github.com/pstuifzand/ekster/pkg/util"
|
||||||
|
|
||||||
|
"github.com/alecthomas/template"
|
||||||
|
"github.com/garyburd/redigo/redis"
|
||||||
|
"willnorris.com/go/microformats"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mainHandler struct {
|
type mainHandler struct {
|
||||||
|
@ -67,6 +69,7 @@ type authPage struct {
|
||||||
RedirectURI string
|
RedirectURI string
|
||||||
State string
|
State string
|
||||||
Channels []microsub.Channel
|
Channels []microsub.Channel
|
||||||
|
App app
|
||||||
}
|
}
|
||||||
|
|
||||||
type authRequest struct {
|
type authRequest struct {
|
||||||
|
@ -196,6 +199,49 @@ func performIndieauthCallback(r *http.Request, sess *session) (bool, *authRespon
|
||||||
return verifyAuthCode(code, sess.RedirectURI, sess.AuthorizationEndpoint)
|
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) {
|
func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
conn := pool.Get()
|
conn := pool.Get()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
@ -392,6 +438,9 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
page.State = state
|
page.State = state
|
||||||
page.Channels, err = h.Backend.ChannelsGetList()
|
page.Channels, err = h.Backend.ChannelsGetList()
|
||||||
|
|
||||||
|
app, err := getAppInfo(clientID)
|
||||||
|
page.App = app
|
||||||
|
|
||||||
err = h.Templates.ExecuteTemplate(w, "auth.html", page)
|
err = h.Templates.ExecuteTemplate(w, "auth.html", page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(w, "ERROR: %q\n", err)
|
fmt.Fprintf(w, "ERROR: %q\n", err)
|
||||||
|
|
|
@ -50,6 +50,12 @@
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<p>{{ .ClientID }}</p>
|
<p>{{ .ClientID }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<p>{{ .App.Name }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<p><img src="{{ .App.IconURL }}" /></p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user