tenseleyflow/shithub / 525c79a

Browse files

web: wire DeviceCodeAPIMounter into CSRF-exempt group

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
525c79a5578fcca23c1bea81d4c439c068a9c033
Parents
f372f5b
Tree
cfac7e8

2 changed files

StatusFile+-
M internal/web/handlers/handlers.go 9 0
M internal/web/server.go 1 0
internal/web/handlers/handlers.gomodified
@@ -56,6 +56,12 @@ type Deps struct {
5656
 	// group so the API surface (PAT-authenticated, no browser-form
5757
 	// posts) can register its routes.
5858
 	APIMounter func(chi.Router)
59
+	// DeviceCodeAPIMounter, when non-nil, registers the RFC 8628
60
+	// device-code JSON endpoints (/login/device/code +
61
+	// /login/oauth/access_token) on the CSRF-exempt group. The
62
+	// matching browser-facing /login/device verification page is
63
+	// mounted by AuthMounter (CSRF-protected).
64
+	DeviceCodeAPIMounter func(chi.Router)
5965
 	// AvatarMounter, when non-nil, registers /avatars/{username} on the
6066
 	// CSRF-exempt group (avatar GETs are safe and benefit from caching).
6167
 	AvatarMounter func(chi.Router)
@@ -241,6 +247,9 @@ func RegisterChi(r *chi.Mux, deps Deps) (*chi.Mux, middleware.PanicHandler, http
241247
 		if deps.APIMounter != nil {
242248
 			deps.APIMounter(r)
243249
 		}
250
+		if deps.DeviceCodeAPIMounter != nil {
251
+			deps.DeviceCodeAPIMounter(r)
252
+		}
244253
 		if deps.AvatarMounter != nil {
245254
 			deps.AvatarMounter(r)
246255
 		}
internal/web/server.gomodified
@@ -168,6 +168,7 @@ func Run(ctx context.Context, opts Options) error {
168168
 			return fmt.Errorf("auth handlers: %w", err)
169169
 		}
170170
 		deps.AuthMounter = auth.Mount
171
+		deps.DeviceCodeAPIMounter = auth.MountDeviceCodeAPI
171172
 
172173
 		var (
173174
 			runnerJWT  *runnerjwt.Signer