Skip to content
Snippets Groups Projects
Commit dcc97ce0 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Only pass around the port for auto tokens.

parent f5661c0b
Branches
No related tags found
No related merge requests found
...@@ -178,7 +178,7 @@ func Sign(pub ssh.PublicKey, token string, conf *Config) (*ssh.Certificate, erro ...@@ -178,7 +178,7 @@ func Sign(pub ssh.PublicKey, token string, conf *Config) (*ssh.Certificate, erro
// Listener type contains information for the client listener. // Listener type contains information for the client listener.
type Listener struct { type Listener struct {
srv *http.Server srv *http.Server
ReceiverURL string Port int
Token chan string Token chan string
} }
...@@ -188,9 +188,9 @@ func StartHTTPServer() *Listener { ...@@ -188,9 +188,9 @@ func StartHTTPServer() *Listener {
srv: &http.Server{}, srv: &http.Server{},
Token: make(chan string), Token: make(chan string),
} }
authCallbackURL := "/auth/callback" // TODO: Random? authCallbackPath := "/auth/callback" // TODO: Random?
http.HandleFunc(authCallbackURL, http.HandleFunc(authCallbackPath,
func(w http.ResponseWriter, r *http.Request) { func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte("<html><head><title>Authorized</title></head><body>Authorized. You can now close this window.</body></html>")) w.Write([]byte("<html><head><title>Authorized</title></head><body>Authorized. You can now close this window.</body></html>"))
...@@ -203,9 +203,7 @@ func StartHTTPServer() *Listener { ...@@ -203,9 +203,7 @@ func StartHTTPServer() *Listener {
if err != nil { if err != nil {
return nil return nil
} }
port := l.Addr().(*net.TCPAddr).Port listener.Port = l.Addr().(*net.TCPAddr).Port
listener.ReceiverURL = fmt.Sprintf("http://localhost:%d%s",
port, authCallbackURL)
go func() { go func() {
err := listener.srv.Serve(l) err := listener.srv.Serve(l)
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"net/url"
"os" "os"
"os/user" "os/user"
"path" "path"
...@@ -55,8 +54,7 @@ func main() { ...@@ -55,8 +54,7 @@ func main() {
if c.AutoToken { if c.AutoToken {
listener = client.StartHTTPServer() listener = client.StartHTTPServer()
if listener != nil { if listener != nil {
authURL = fmt.Sprintf("%s?auto_token=%s", authURL = fmt.Sprintf("%s?auto_token=%d", c.CA, listener.Port)
c.CA, url.PathEscape(listener.ReceiverURL))
} }
} }
fmt.Printf("Your browser has been opened to visit %s\n", authURL) fmt.Printf("Your browser has been opened to visit %s\n", authURL)
......
...@@ -116,10 +116,11 @@ func (a *app) auth(w http.ResponseWriter, r *http.Request) { ...@@ -116,10 +116,11 @@ func (a *app) auth(w http.ResponseWriter, r *http.Request) {
func (a *app) index(w http.ResponseWriter, r *http.Request) { func (a *app) index(w http.ResponseWriter, r *http.Request) {
tok := a.getAuthToken(r) tok := a.getAuthToken(r)
autoTokenURL := a.getSessionVariable(r, "auto_token") autoToken := a.getSessionVariable(r, "auto_token")
if autoTokenURL != "" { if autoToken != "" {
http.Redirect(w, r, fmt.Sprintf("%s?token=%s", http.Redirect(w, r,
autoTokenURL, tok.AccessToken), http.StatusSeeOther) fmt.Sprintf("http://localhost:%s/auth/callback?token=%s",
autoToken, tok.AccessToken), http.StatusSeeOther)
} else { } else {
page := struct { page := struct {
Token string Token string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment