简体   繁体   English

从二头肌中的 Azure 应用服务访问应用(客户端)ID

[英]Accessing the App (client) ID from an Azure App Service in bicep

In bicep, I am configuring an Azure API Management policy that enables the managed service identity for a specific backend App Service.在二头肌中,我正在配置一个 Azure API 管理策略,该策略为特定的后端应用服务启用托管服务标识。

This is typically done by setting an XML fragment like this:这通常通过像这样设置 XML 片段来完成:

<policies>
    <inbound>
        <authentication-managed-identity resource="4d192d04-XXXX-461f-a6ab-XXXXXXXXXXXX" />
        <base />
    </inbound>
</policies>

What I am now looking for, is how to retrieve that specific resource id from the existing App Service, in my bicep template.我现在正在寻找的是如何在我的二头肌模板中从现有应用服务中检索该特定resource ID。

Some fragments from my existing bicep template below:下面是我现有的二头肌模板中的一些片段:

// The App Service declaration
@description('API Website')
resource backendapi 'Microsoft.Web/sites@2021-03-01' = {
  name: 'backend-${environment}'
  kind: 'app,linux,container'
  location: location
  // left out properties, etc for brevity

// This is where I want to retrieve the client ID from that web app, but this fails:
var managed_identity_id = backendapi.identity.principalId

When deploying the above template, I get the following exception (although the identity.principalId was indicated to be valid by the Visual Studio Code intellisense.部署上述模板时,出现以下异常(尽管 Visual Studio Code intellisense 指示identity.principalId有效。

The language expression property 'identity' doesn't exist, available properties are 'apiVersion, location, tags, kind, properties, condition, deploymentResourceLineInfo, existing, isConditionTrue, subscriptionId, resourceGroupName, scope, resourceId, referenceApiVersion, isTemplateResource, isAction, provisioningOperation'语言表达式属性“身份”不存在,可用属性为“apiVersion、位置、标签、种类、属性、条件、deploymentResourceLineInfo、现有、isConditionTrue、subscriptionId、resourceGroupName、范围、resourceId、referenceApiVersion、isTemplateResource、isAction、provisioningOperation”

So my question is, how can I access the property from an App Service, in a bicep file.所以我的问题是,如何在二头肌文件中从应用服务访问该属性。 The property of which the value is shown in the following screenshot:其值显示在以下屏幕截图中的属性:

截屏

As explained in the comment section, you are looking for the web app auth settings: Microsoft.Web sites/config 'authsettingsV2' 2020-12-01如评论部分所述,您正在寻找 Web 应用身份验证设置: Microsoft.Web sites/config 'authsettingsV2' 2020-12-01

You could retrieve the clientId for AzureAD Auth Like that:您可以像这样检索 AzureAD Auth 的 clientId:

param webAppName string

resource authsettings 'Microsoft.Web/sites/config@2020-12-01' existing = {
  name: '${webAppName}/authsettingsV2'
}

var clientId = authsettings.properties.identityProviders.azureActiveDirectory.registration.clientId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure Bicep 为 Azure 应用服务计划部署提供 InvalidTemplateDeployment 错误 - Azure Bicep giving InvalidTemplateDeployment error for Azure App Service Plan deployment 从客户端应用程序访问SQL Azure - Accessing SQL Azure from client app 如何使用 Bicep 使用 .Net 堆栈部署 windows Azure App Service? - How to deploy windows Azure App Service with .Net stack using Bicep? Azure bicep 获取服务主体的应用程序 ID - Azure bicep get application id of service principal 从 azure 应用服务访问虚拟机上的服务 - Accessing service on a Virtual Machine from azure app service 对于具有托管身份的Azure应用服务,如何检索客户端ID - For an Azure App service with a managed identity, how to retrieve the Client ID 我正在尝试使用 Bicep 模板将带有服务总线部署的逻辑应用程序部署到 azure 应用程序 - I am trying to deploy a Logic-App with a Service-Bus Deploy to azure app using Bicep template 从SharePoint Online访问Azure应用代理服务 - Accessing Azure App Proxy service from SharePoint Online 如何在 azure bicep 部署模板中获取 linux 应用服务的主机 url - How to get the host url of a linux app service in azure bicep deployment templates 检索 Synapse 服务主体的应用程序 ID,并使用 Bicep 作为管理员添加到 AAS - Retrieve app id of Synapse service principal and add as administrator to AAS using Bicep
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM