Add CORS headers to /verify endpoint

This commit is contained in:
Melon 2023-12-14 23:41:39 +00:00
parent 67be57b6b1
commit be3a09b73a
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -63,11 +63,11 @@ func NewHttpServer(conf Conf, signer mjwt.Signer) *HttpServer {
rw.WriteHeader(http.StatusOK)
_, _ = fmt.Fprintln(rw, "What is this?")
})
r.POST("/verify", hs.verifyHandler)
r.GET("/popup", hs.flowPopup)
r.POST("/popup", hs.flowPopupPost)
r.GET("/callback", hs.flowCallback)
// setup CORS options for `/verify` and `/refresh` endpoints
var corsAccessControl = cors.New(cors.Options{
AllowOriginFunc: func(origin string) bool {
load := hs.services.Load()
@ -78,6 +78,13 @@ func NewHttpServer(conf Conf, signer mjwt.Signer) *HttpServer {
AllowedHeaders: []string{"Content-Type"},
AllowCredentials: true,
})
// `/verify` and `/refresh` need CORS headers to be usable on other domains
r.POST("/verify", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
corsAccessControl.ServeHTTP(rw, req, func(writer http.ResponseWriter, request *http.Request) {
hs.verifyHandler(rw, req, params)
})
})
r.POST("/refresh", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
corsAccessControl.ServeHTTP(rw, req, func(writer http.ResponseWriter, request *http.Request) {
hs.refreshHandler(rw, req, params)