PublicDashboards: Validate access token (#57298)

Adding validation for access token
This commit is contained in:
lean.dev
2022-10-20 16:43:33 -03:00
committed by GitHub
parent 5ee4744d62
commit 552d9d70eb
6 changed files with 118 additions and 59 deletions
@@ -10,7 +10,7 @@ import (
"github.com/grafana/grafana/pkg/web"
)
// Adds orgId to context based on org of public dashboard
// SetPublicDashboardOrgIdOnContext Adds orgId to context based on org of public dashboard
func SetPublicDashboardOrgIdOnContext(publicDashboardService publicdashboards.Service) func(c *models.ReqContext) {
return func(c *models.ReqContext) {
accessToken, ok := web.Params(c.Req)[":accessToken"]
@@ -28,14 +28,15 @@ func SetPublicDashboardOrgIdOnContext(publicDashboardService publicdashboards.Se
}
}
// Adds public dashboard flag on context
// SetPublicDashboardFlag Adds public dashboard flag on context
func SetPublicDashboardFlag(c *models.ReqContext) {
c.IsPublicDashboardView = true
}
// Middleware to enforce that a public dashboards exists before continuing to
// handler
func RequiresValidAccessToken(publicDashboardService publicdashboards.Service) func(c *models.ReqContext) {
// RequiresExistingAccessToken Middleware to enforce that a public dashboards exists before continuing to handler. This
// method will query the database to ensure that it exists.
// Use when we want to enforce a public dashboard is valid on an endpoint we do not maintain
func RequiresExistingAccessToken(publicDashboardService publicdashboards.Service) func(c *models.ReqContext) {
return func(c *models.ReqContext) {
accessToken, ok := web.Params(c.Req)[":accessToken"]