@@ -13,6 +13,7 @@ import (
1313 "os/exec"
1414 "path/filepath"
1515 "runtime"
16+ "strconv"
1617 "strings"
1718 "time"
1819
@@ -82,6 +83,7 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
8283 // Define a handler that will get the authorization code, call the token endpoint, and close the HTTP server
8384 var errServer error
8485 mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
86+ p .Debug (print .DebugLevel , "received request from authentication server" )
8587 // Close the server only if there was an error
8688 // Otherwise, it will redirect to the succesfull login page
8789 defer func () {
@@ -98,19 +100,31 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
98100 return
99101 }
100102
103+ p .Debug (print .DebugLevel , "trading authorization code for access and refresh tokens" )
104+
101105 // Trade the authorization code and the code verifier for access and refresh tokens
102106 accessToken , refreshToken , err := getUserAccessAndRefreshTokens (authDomain , clientId , codeVerifier , code , redirectURL )
103107 if err != nil {
104108 errServer = fmt .Errorf ("retrieve tokens: %w" , err )
105109 return
106110 }
107111
112+ p .Debug (print .DebugLevel , "received response from the authentication server" )
113+
108114 sessionExpiresAtUnix , err := getStartingSessionExpiresAtUnix ()
109115 if err != nil {
110116 errServer = fmt .Errorf ("compute session expiration timestamp: %w" , err )
111117 return
112118 }
113119
120+ sessionExpiresAtUnixInt , err := strconv .Atoi (sessionExpiresAtUnix )
121+ if err != nil {
122+ p .Debug (print .ErrorLevel , "parse session expiration value \" %s\" : %s" , sessionExpiresAtUnix , err )
123+ } else {
124+ sessionExpiresAt := time .Unix (int64 (sessionExpiresAtUnixInt ), 0 )
125+ p .Debug (print .DebugLevel , "session expires at %s" , sessionExpiresAt )
126+ }
127+
114128 err = SetAuthFlow (AUTH_FLOW_USER_TOKEN )
115129 if err != nil {
116130 errServer = fmt .Errorf ("set auth flow type: %w" , err )
@@ -123,6 +137,8 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
123137 return
124138 }
125139
140+ p .Debug (print .DebugLevel , "user %s logged in successfully" , email )
141+
126142 authFields := map [authFieldKey ]string {
127143 SESSION_EXPIRES_AT_UNIX : sessionExpiresAtUnix ,
128144 ACCESS_TOKEN : accessToken ,
@@ -137,6 +153,8 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
137153
138154 // Redirect the user to the successful login page
139155 loginSuccessURL := redirectURL + loginSuccessPath
156+
157+ p .Debug (print .DebugLevel , "redirecting browser to login successful page" )
140158 http .Redirect (w , r , loginSuccessURL , http .StatusSeeOther )
141159 })
142160
@@ -163,6 +181,9 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
163181 }
164182 })
165183
184+ p .Debug (print .DebugLevel , "opening browser for authentication" )
185+ p .Debug (print .DebugLevel , "using authentication server on %s" , authDomain )
186+
166187 // Open a browser window to the authorizationURL
167188 err = openBrowser (authorizationURL )
168189 if err != nil {
@@ -171,6 +192,7 @@ func AuthorizeUser(p *print.Printer, isReauthentication bool) error {
171192
172193 // Start the blocking web server loop
173194 // It will exit when the handlers get fired and call server.Close()
195+ p .Debug (print .DebugLevel , "listening for response from authentication server on %s" , redirectURL )
174196 err = server .Serve (listener )
175197 if ! errors .Is (err , http .ErrServerClosed ) {
176198 return fmt .Errorf ("server for PKCE flow closed unexpectedly: %w" , err )
0 commit comments