fix: allow multiple config api service names
This commit is contained in:
@@ -41,7 +41,7 @@ func Authorize(r *ghttp.Request) bool {
|
|||||||
signature := strings.TrimSpace(r.Header.Get(headerSignature))
|
signature := strings.TrimSpace(r.Header.Get(headerSignature))
|
||||||
expectedService := g.Cfg().MustGet(ctx, "imConfigApi.serviceName", "im-server").String()
|
expectedService := g.Cfg().MustGet(ctx, "imConfigApi.serviceName", "im-server").String()
|
||||||
secret := configuredSecret(r)
|
secret := configuredSecret(r)
|
||||||
if serviceName == "" || timestampRaw == "" || nonce == "" || signature == "" || serviceName != expectedService || secret == "" {
|
if serviceName == "" || timestampRaw == "" || nonce == "" || signature == "" || !isAllowedService(serviceName, expectedService) || secret == "" {
|
||||||
writeAuthError(r, http.StatusUnauthorized, "internal signature required")
|
writeAuthError(r, http.StatusUnauthorized, "internal signature required")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -85,6 +85,19 @@ func Authorize(r *ghttp.Request) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAllowedService(serviceName, expectedServices string) bool {
|
||||||
|
serviceName = strings.TrimSpace(serviceName)
|
||||||
|
if serviceName == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, expected := range strings.Split(expectedServices, ",") {
|
||||||
|
if serviceName == strings.TrimSpace(expected) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func configuredSecret(r *ghttp.Request) string {
|
func configuredSecret(r *ghttp.Request) string {
|
||||||
ctx := r.GetCtx()
|
ctx := r.GetCtx()
|
||||||
secret := g.Cfg().MustGet(ctx, "imConfigApi.serviceSecret").String()
|
secret := g.Cfg().MustGet(ctx, "imConfigApi.serviceSecret").String()
|
||||||
|
|||||||
@@ -326,6 +326,6 @@ imWorkbenchApi:
|
|||||||
timeout: "5s"
|
timeout: "5s"
|
||||||
|
|
||||||
imConfigApi:
|
imConfigApi:
|
||||||
serviceName: "im-server"
|
serviceName: "im-server,im-workbench"
|
||||||
serviceSecret: "${IM_CONFIG_API_SECRET}"
|
serviceSecret: "${IM_CONFIG_API_SECRET}"
|
||||||
timeWindow: "300s"
|
timeWindow: "300s"
|
||||||
|
|||||||
Reference in New Issue
Block a user