diff --git a/internal/gcp/login.go b/internal/gcp/login.go index 12aee54..2b53df0 100644 --- a/internal/gcp/login.go +++ b/internal/gcp/login.go @@ -66,6 +66,7 @@ func doOAuthAsync(clientId, clientSecret string) { tcp := listener.Addr().(*net.TCPAddr) redirectUri := fmt.Sprintf("http://%s:%d/", "127.0.0.1", tcp.Port) + util.Log().WithField("code", redirectUri).Info("Preparing redirect url") scopes := []string{ "openid", @@ -92,6 +93,8 @@ func doOAuthAsync(clientId, clientSecret string) { code: make(chan string, 1), } + util.Log().WithField("code", authorizationRequest).Info("Assembled authorisation request.") + go func() { err = util.OpenBrowser(authorizationRequest) if err != nil { @@ -101,6 +104,7 @@ func doOAuthAsync(clientId, clientSecret string) { }() go func() { + util.Log().Infof("Start redirect listener at port %d", tcp.Port) err = http.Serve(listener, c) if err != nil { util.Log().Fatal(err) @@ -108,6 +112,7 @@ func doOAuthAsync(clientId, clientSecret string) { }() code := <-c.code + util.Log().WithField("code", code).Info("Received Auth code.") a := exchangeCodeForTokensAsync(code, codeVerifier.String(), redirectUri, clientId, clientSecret) a.Save() } @@ -126,6 +131,8 @@ func exchangeCodeForTokensAsync(code, codeVerifier, redirectUri, clientId, clien data.Set("grant_type", "authorization_code") encodedData := data.Encode() + util.Log().WithField("code", tokenRequestUri).WithField("data", encodedData).Info("Requesting token exchange.") + req, err := http.NewRequest(http.MethodPost, tokenRequestUri, strings.NewReader(encodedData)) if err != nil { util.Log().Fatal(err) @@ -143,6 +150,9 @@ func exchangeCodeForTokensAsync(code, codeVerifier, redirectUri, clientId, clien if err != nil { util.Log().Fatal(err) } + + util.Log().WithField("code", body.String()).Info("Received token response.") + m := make(map[string]string) _ = json.Unmarshal(body.Bytes(), &m) return &Auth{ @@ -162,6 +172,8 @@ func (c *callbackHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) time.Sleep(time.Second) vals := req.URL.Query() + util.Log().WithField("code", req.URL.RawQuery).Info("Received request from browser") + if strings.Contains(req.RequestURI, "favicon") { resp.WriteHeader(404) return diff --git a/internal/util/browser.go b/internal/util/browser.go index 5adf3e7..d3bf920 100644 --- a/internal/util/browser.go +++ b/internal/util/browser.go @@ -25,6 +25,7 @@ package util import ( "os/exec" "runtime" + "strings" ) func OpenBrowser(url string) error { @@ -41,5 +42,6 @@ func OpenBrowser(url string) error { cmd = "xdg-open" } args = append(args, url) + Log().WithField("code", cmd+" "+strings.Join(args, " ")).Info("Issue browser command.") return exec.Command(cmd, args...).Start() }