mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 07:34:06 +00:00
Add CORS headers to /verify endpoint
This commit is contained in:
parent
67be57b6b1
commit
be3a09b73a
@ -63,11 +63,11 @@ func NewHttpServer(conf Conf, signer mjwt.Signer) *HttpServer {
|
|||||||
rw.WriteHeader(http.StatusOK)
|
rw.WriteHeader(http.StatusOK)
|
||||||
_, _ = fmt.Fprintln(rw, "What is this?")
|
_, _ = fmt.Fprintln(rw, "What is this?")
|
||||||
})
|
})
|
||||||
r.POST("/verify", hs.verifyHandler)
|
|
||||||
r.GET("/popup", hs.flowPopup)
|
r.GET("/popup", hs.flowPopup)
|
||||||
r.POST("/popup", hs.flowPopupPost)
|
r.POST("/popup", hs.flowPopupPost)
|
||||||
r.GET("/callback", hs.flowCallback)
|
r.GET("/callback", hs.flowCallback)
|
||||||
|
|
||||||
|
// setup CORS options for `/verify` and `/refresh` endpoints
|
||||||
var corsAccessControl = cors.New(cors.Options{
|
var corsAccessControl = cors.New(cors.Options{
|
||||||
AllowOriginFunc: func(origin string) bool {
|
AllowOriginFunc: func(origin string) bool {
|
||||||
load := hs.services.Load()
|
load := hs.services.Load()
|
||||||
@ -78,6 +78,13 @@ func NewHttpServer(conf Conf, signer mjwt.Signer) *HttpServer {
|
|||||||
AllowedHeaders: []string{"Content-Type"},
|
AllowedHeaders: []string{"Content-Type"},
|
||||||
AllowCredentials: true,
|
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) {
|
r.POST("/refresh", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
corsAccessControl.ServeHTTP(rw, req, func(writer http.ResponseWriter, request *http.Request) {
|
corsAccessControl.ServeHTTP(rw, req, func(writer http.ResponseWriter, request *http.Request) {
|
||||||
hs.refreshHandler(rw, req, params)
|
hs.refreshHandler(rw, req, params)
|
||||||
|
Loading…
Reference in New Issue
Block a user