Use baseurl as ClientID
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2019-08-09 20:47:27 +02:00
parent 9a67eb203e
commit c7a1e65b50
Signed by: peter
GPG Key ID: 374322D56E5209E8
2 changed files with 6 additions and 15 deletions

View File

@ -153,10 +153,10 @@ func saveSession(sessionVar string, sess *session, conn redis.Conn) error {
return err return err
} }
func verifyAuthCode(code, redirectURI, authEndpoint string) (bool, *authResponse, error) { func verifyAuthCode(code, redirectURI, authEndpoint, clientID string) (bool, *authResponse, error) {
reqData := url.Values{} reqData := url.Values{}
reqData.Set("code", code) reqData.Set("code", code)
reqData.Set("client_id", ClientID) reqData.Set("client_id", clientID)
reqData.Set("redirect_uri", redirectURI) reqData.Set("redirect_uri", redirectURI)
req, err := http.NewRequest(http.MethodPost, authEndpoint, strings.NewReader(reqData.Encode())) req, err := http.NewRequest(http.MethodPost, authEndpoint, strings.NewReader(reqData.Encode()))
@ -206,14 +206,14 @@ func isLoggedIn(backend *memoryBackend, sess *session) bool {
return true return true
} }
func performIndieauthCallback(r *http.Request, sess *session) (bool, *authResponse, error) { func performIndieauthCallback(clientID string, r *http.Request, sess *session) (bool, *authResponse, error) {
state := r.Form.Get("state") state := r.Form.Get("state")
if state != sess.State { if state != sess.State {
return false, &authResponse{}, fmt.Errorf("mismatched state") return false, &authResponse{}, fmt.Errorf("mismatched state")
} }
code := r.Form.Get("code") code := r.Form.Get("code")
return verifyAuthCode(code, sess.RedirectURI, sess.AuthorizationEndpoint) return verifyAuthCode(code, sess.RedirectURI, sess.AuthorizationEndpoint, clientID)
} }
type app struct { type app struct {
@ -301,7 +301,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sessionVar := c.Value sessionVar := c.Value
sess, err := loadSession(sessionVar, conn) sess, err := loadSession(sessionVar, conn)
verified, authResponse, err := performIndieauthCallback(r, &sess) verified, authResponse, err := performIndieauthCallback(h.BaseURL, r, &sess)
if err != nil { if err != nil {
fmt.Fprintf(w, "ERROR: %q\n", err) fmt.Fprintf(w, "ERROR: %q\n", err)
return return
@ -520,7 +520,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
authenticationURL := indieauth.CreateAuthenticationURL(*endpoints.AuthorizationEndpoint, endpoints.Me.String(), ClientID, redirectURI, state) authenticationURL := indieauth.CreateAuthenticationURL(*endpoints.AuthorizationEndpoint, endpoints.Me.String(), h.BaseURL, redirectURI, state)
http.Redirect(w, r, authenticationURL, 302) http.Redirect(w, r, authenticationURL, 302)
return return

View File

@ -30,11 +30,6 @@ import (
"p83.nl/go/ekster/pkg/server" "p83.nl/go/ekster/pkg/server"
) )
const (
// ClientID is used to identify the server when we make authentication requests.
ClientID string = "https://p83.nl/microsub-client"
)
// AppOptions are options for the app // AppOptions are options for the app
type AppOptions struct { type AppOptions struct {
Port int Port int
@ -46,10 +41,6 @@ type AppOptions struct {
pool *redis.Pool pool *redis.Pool
} }
var (
// pool *redis.Pool
)
func init() { func init() {
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime) log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
} }