Browse Source

Redirect even if already authed if a redirect URL is given

pull/36/head
Kegan Dougal 8 years ago
parent
commit
b643b8c797
  1. 11
      src/github.com/matrix-org/go-neb/realms/github/github.go

11
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") logger.WithField("user_id", ghSession.UserID()).Print("Mapped redirect to user")
if ghSession.AccessToken != "" && ghSession.Scopes != "" { 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 return
} }
@ -223,14 +223,19 @@ func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request
failWith(logger, w, 500, "Failed to persist session", err) failWith(logger, w, 500, "Failed to persist session", err)
return 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 != "" { if ghSession.ClientsRedirectURL != "" {
w.WriteHeader(302) w.WriteHeader(302)
w.Header().Set("Location", ghSession.ClientsRedirectURL) w.Header().Set("Location", ghSession.ClientsRedirectURL)
// technically don't need a body but *shrug* // technically don't need a body but *shrug*
w.Write([]byte(ghSession.ClientsRedirectURL)) w.Write([]byte(ghSession.ClientsRedirectURL))
} else { } else {
w.WriteHeader(200)
w.Write([]byte("You have successfully linked your Github account to " + ghSession.UserID()))
failWith(logger, w, code, msg, nil)
} }
} }

Loading…
Cancel
Save