diff --git a/jwk/handler.go b/jwk/handler.go index 6ffca6942d1..8262d953acb 100644 --- a/jwk/handler.go +++ b/jwk/handler.go @@ -72,6 +72,7 @@ func (h *Handler) GetGenerators() map[string]KeyGenerator { } func (h *Handler) SetRoutes(frontend, backend *httprouter.Router, corsMiddleware func(http.Handler) http.Handler) { + frontend.Handler("OPTIONS", WellKnownKeysPath, corsMiddleware(http.HandlerFunc(h.handleOptions))) frontend.Handler("GET", WellKnownKeysPath, corsMiddleware(http.HandlerFunc(h.WellKnown))) backend.GET(KeyHandlerPath+"/:set/:key", h.GetKey) backend.GET(KeyHandlerPath+"/:set", h.GetKeySet) @@ -390,3 +391,7 @@ func (h *Handler) DeleteKey(w http.ResponseWriter, r *http.Request, ps httproute w.WriteHeader(http.StatusNoContent) } + +// This function will not be called, OPTIONS request will be handled by cors +// this is just a placeholder. +func (h *Handler) handleOptions(w http.ResponseWriter, r *http.Request) {} \ No newline at end of file diff --git a/oauth2/handler.go b/oauth2/handler.go index 023fcf3187d..2d92a8b89b7 100644 --- a/oauth2/handler.go +++ b/oauth2/handler.go @@ -157,14 +157,18 @@ type FlushInactiveOAuth2TokensRequest struct { } func (h *Handler) SetRoutes(frontend, backend *httprouter.Router, corsMiddleware func(http.Handler) http.Handler) { + frontend.Handler("OPTIONS", TokenPath, corsMiddleware(http.HandlerFunc(h.handleOptions))) frontend.Handler("POST", TokenPath, corsMiddleware(http.HandlerFunc(h.TokenHandler))) frontend.GET(AuthPath, h.AuthHandler) frontend.POST(AuthPath, h.AuthHandler) frontend.GET(DefaultConsentPath, h.DefaultConsentHandler) frontend.GET(DefaultErrorPath, h.DefaultErrorHandler) frontend.GET(DefaultLogoutPath, h.DefaultLogoutHandler) + frontend.Handler("OPTIONS", RevocationPath, corsMiddleware(http.HandlerFunc(h.handleOptions))) frontend.Handler("POST", RevocationPath, corsMiddleware(http.HandlerFunc(h.RevocationHandler))) + frontend.Handler("OPTIONS", WellKnownPath, corsMiddleware(http.HandlerFunc(h.handleOptions))) frontend.Handler("GET", WellKnownPath, corsMiddleware(http.HandlerFunc(h.WellKnownHandler))) + frontend.Handler("OPTIONS", UserinfoPath, corsMiddleware(http.HandlerFunc(h.handleOptions))) frontend.Handler("GET", UserinfoPath, corsMiddleware(http.HandlerFunc(h.UserinfoHandler))) frontend.Handler("POST", UserinfoPath, corsMiddleware(http.HandlerFunc(h.UserinfoHandler))) @@ -675,3 +679,7 @@ func (h *Handler) writeAuthorizeError(w http.ResponseWriter, ar fosite.Authorize h.OAuth2.WriteAuthorizeError(w, ar, err) } + +// This function will not be called, OPTIONS request will be handled by cors +// this is just a placeholder. +func (h *Handler) handleOptions(w http.ResponseWriter, r *http.Request) {}