Skip to content

Commit f545106

Browse files
tommytroenybelMekktronghnchristeredvartsen
committed
fix: handle GET requests only in auth handlerfuncs
* we receive an OPTIONS request (chrome) first which ends the authflow if we do not separate GET and OPTIONS * https://issues.chromium.org/issues/330594669 Co-authored-by: ybelmekk <[email protected]> Co-authored-by: tronghn <[email protected]> Co-authored-by: christeredvartsen <[email protected]>
1 parent 6dd537d commit f545106

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

internal/device-agent/auth/azure.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ func handleRedirectAzure(state string, conf oauth2.Config, codeVerifier *codever
2828
return
2929
}
3030

31-
// We used to use r.Context() here, but a Google Chrome update broke that.
32-
// It seems that Chrome closes the HTTP connection prematurely, because the context
33-
// is at this point already canceled.
34-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
31+
ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(30*time.Second))
3532
defer cancel()
3633

3734
codeVerifierParam := oauth2.SetAuthURLParam("code_verifier", codeVerifier.String())

internal/device-agent/auth/common.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func GetDeviceAgentToken(ctx context.Context, log logrus.FieldLogger, conf oauth
4545

4646
handler := http.NewServeMux()
4747
// define a handler that will get the authorization code, call the authFlowResponse endpoint, and close the HTTP server
48-
handler.HandleFunc("/", handleRedirectAzure(state, conf, codeVerifier, authFlowChan))
49-
handler.HandleFunc("/google", handleRedirectGoogle(state, conf.RedirectURL, codeVerifier, authFlowChan, authServer))
48+
handler.HandleFunc("GET /", handleRedirectAzure(state, conf, codeVerifier, authFlowChan))
49+
handler.HandleFunc("GET /google", handleRedirectGoogle(state, conf.RedirectURL, codeVerifier, authFlowChan, authServer))
5050

5151
server := &http.Server{Handler: handler}
5252
go server.Serve(listener)

internal/device-agent/auth/google.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ func handleRedirectGoogle(state, redirectURI string, codeVerifier *codeverifier.
3838
return
3939
}
4040

41-
// We used to use r.Context() here, but a Google Chrome update broke that.
42-
// It seems that Chrome closes the HTTP connection prematurely, because the context
43-
// is at this point already canceled.
44-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(10*time.Second))
41+
ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(10*time.Second))
4542
defer cancel()
4643

4744
exchangeRequest := ExchangeRequest{

0 commit comments

Comments
 (0)