如何在Azure静态Web应用配置文件中引用配置项动态值?
Azure静态Web应用配置文件引用配置值的正确格式
针对你的问题,分两种场景说明正确的引用方式:
1. 身份认证相关的配置项(clientId/clientSecret)
对于clientIdSettingName和clientSecretSettingName这两个字段,直接填写配置标签页中的键名即可,不需要额外格式包裹。你当前配置里的"CLIENT_ID"和"CLIENT_SECRET"写法是正确的,静态Web应用会自动读取配置标签页中对应键的取值。
2. 普通字段引用配置值(比如openId配置地址)
对于wellKnownOpenIdConfiguration这类需要直接插入配置值的字段,正确格式是@env('配置键名')。你之前用的"{OPENID_CONFIG_URL}"是错误的,需要替换成@env('OPENID_CONFIG_URL')。
修正后的完整配置文件
{ "auth": { "identityProviders": { "customOpenIdConnectProviders": { "identityprovider": { "registration": { "clientIdSettingName": "CLIENT_ID", "clientCredential": { "clientSecretSettingName": "CLIENT_SECRET" }, "openIdConnectConfiguration": { "wellKnownOpenIdConfiguration": "@env('OPENID_CONFIG_URL')" } }, "login": { "nameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uid", "scopes": ["openid", "profile"], "loginParameterNames": [] } } } } }, "navigationFallback": { "rewrite": "index.html", "exclude": ["/static/media/*.{png,jpg,jpeg,gif,bmp}", "/static/css/*"] }, "mimeTypes": { ".json": "text/json" }, "routes": [ { "route": "/", "allowedRoles": ["authenticated"] } ], "responseOverrides": { "401": { "statusCode": 302, "redirect": "/.auth/login/test" } } }
你尝试的${"CLIENT_ID"}、$("CLIENT_ID"}、$(CLIENT_ID}这些格式都不符合Azure静态Web应用的配置引用规则,所以无法生效。
内容的提问来源于stack exchange,提问作者Maddy
相关产品推荐
相关产品推荐

