From b643b8c7979bc8a6b335552f686d7f2e7bb29edc Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 19 Aug 2016 09:35:57 +0100 Subject: [PATCH] Redirect even if already authed if a redirect URL is given --- .../matrix-org/go-neb/realms/github/github.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/realms/github/github.go b/src/github.com/matrix-org/go-neb/realms/github/github.go index d7c2c69..ce7522f 100644 --- a/src/github.com/matrix-org/go-neb/realms/github/github.go +++ b/src/github.com/matrix-org/go-neb/realms/github/github.go @@ -191,7 +191,7 @@ func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request logger.WithField("user_id", ghSession.UserID()).Print("Mapped redirect to user") if ghSession.AccessToken != "" && ghSession.Scopes != "" { - failWith(logger, w, 400, "You have already authenticated with Github", nil) + r.redirectOr(w, 400, "You have already authenticated with Github", logger, ghSession) return } @@ -223,14 +223,19 @@ func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request failWith(logger, w, 500, "Failed to persist session", err) return } + r.redirectOr( + w, 200, "You have successfully linked your Github account to "+ghSession.UserID(), logger, ghSession, + ) +} + +func (r *GithubRealm) redirectOr(w http.ResponseWriter, code int, msg string, logger *log.Entry, ghSession *GithubSession) { if ghSession.ClientsRedirectURL != "" { w.WriteHeader(302) w.Header().Set("Location", ghSession.ClientsRedirectURL) // technically don't need a body but *shrug* w.Write([]byte(ghSession.ClientsRedirectURL)) } else { - w.WriteHeader(200) - w.Write([]byte("You have successfully linked your Github account to " + ghSession.UserID())) + failWith(logger, w, code, msg, nil) } }