简体   繁体   English

在 azure api 管理中使用 authentication-managed-identity 标签时不完整的 bearer token

[英]Incomplete bearer token when using authentication-managed-identity tag in azure api management

I've been trying to expose an API through azure API Management and I can't figure out what I'm doing wrong.我一直在尝试通过 API azure API Management 公开一个 API,但我不知道自己做错了什么。 Here's the situation:情况是这样的:

  • My API is going to be called from an external application我的 API 将被外部应用程序调用

  • They don't have an Azure Account in the same tenant他们在同一租户中没有 Azure 帐户

  • I want to enable external calls for my API by just using a subscription key (hence, why I'm using API Management), but also want to keep my actual API secured with Azure AD.我想通过使用订阅密钥为我的 API 启用外部呼叫(因此,为什么我使用 API 管理),但也想用 Azure AD 保护我的实际 API。

  • I have an API which is secured with Azure AD using OAuth2 and published into a Windows AppService我有一个 API,它使用 OAuth2 由 Azure AD 保护并发布到 Windows AppService

  • I have an App registration for that API, which i use to authenticate (it works from postman, for example) app registration我有一个 API 的应用程序注册,我用它来进行身份验证(例如,它从 postman 开始工作)应用程序注册

  • I have Managed Identities turned on and permissions set.我已打开托管标识并设置了权限。

  • I have added the API in API management我在API管理中添加了API

  • I added the authentication-managed-identity inbound rule, used the API Id Uri of the app registration as the resource value for it.我添加了authentication-managed-identity入站规则,使用应用程序注册的 API Id Uri 作为它的资源值。 Api Management Config Api 管理配置

  • When testing an endpoint from the APIM interface, I can successfully get a bearer token, but I get a 500 exception from the API which says: Neither scope or roles claim was found in the bearer token bearer response从 APIM 接口测试端点时,我可以成功获取承载令牌,但我从 API 收到 500 异常,它表示:在承载令牌承载响应中找不到 scope 或角色声明

  • Here is the decoded bearer token, it doesn't have a scp attribute bearer decoded这是解码的承载令牌,它没有解码的 scp 属性承载

I'm not sure where I can specify a scope. If I use the full scope uri (api://guid/access.api.management) it will fail when trying to get a bearer token (The resource principal named api://guid/access.api.management was not found in the tenant).我不确定在哪里可以指定 scope。如果我使用完整的 scope uri (api://guid/access.api.management),它会在尝试获取不记名令牌时失败(名为 api 的资源主体:/ /guid/access.api.management 在租户中找不到)。 I've even tried adding the Owner role to the APIM Identity for the AppService.我什至尝试过将 Owner 角色添加到 AppService 的 APIM Identity。

Maybe I'm not using this correctly, I'm pretty new at using Azure cloud and API Management so any suggestions are welcome.也许我没有正确使用它,我在使用 Azure 云和 API 管理方面还很陌生,所以欢迎提出任何建议。 Thanks.谢谢。

You have expose an api protected by Azure, and currently you have an api application .您公开了一个受 Azure 保护的 api,目前您有一个api 应用程序 Next, you need to create another application that represents the client, and then add the client application to the api application.接下来,您需要创建另一个代表客户端的应用程序,然后将客户端应用程序添加到 api 应用程序中。

在此处输入图像描述

Next, go to the client application .接下来,go给客户端申请

  • Under 'API permissions' click on 'Add permission', then click on the ' My APIs ' tab.在“API 权限”下单击“添加权限”,然后单击“我的 API ”选项卡。
  • Find your api application and select the appropriate scope.找到您的 api 应用程序和 select 相应的 scope。
  • Click 'Add permissions'.单击“添加权限”。
  • Grant admin consent for your APIs.为您的 API 授予管理员许可。

在此处输入图像描述

Next, you need to use the auth code flow to obtain an access token,which requires you to log in to the user and obtain the authorization code, and then use the authorization code to redeem the access token.接下来需要使用auth code flow获取access token,需要先登录用户获取授权码,然后使用授权码兑换access token。

1.Request an authorization code in the browser. 1.在浏览器中请求授权码。

https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
client_id={client app client id}
&response_type=code
&redirect_uri={redirect_uri}
&response_mode=query
&scope=api://{api app client id}/{scope name}
&state=12345

2.Redeem token. 2.兑换代币。

在此处输入图像描述

Parse the token:解析令牌:

在此处输入图像描述

I managed to get it working using the client credentials flow and storing the client secret in key vault.我设法使用客户端凭据流并将客户端机密存储在密钥保管库中使其正常工作。

暂无
暂无

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

相关问题 Azure API 管理 + Azure 函数和托管标识 - Azure API Management + Azure Function and managed identity 托管标识是否可用于 API 管理服务和 Azure 函数之间的通信? - Is managed identity available for communication between API Management service and Azure functions? 在Azure API管理中解密承载令牌以获取acr_values - Decrypt bearer token in Azure API Management to get acr_values 使用 Azure AD 承载令牌返回容器列表时身份验证失败 [Azure Blob] [Azure AD OAuth 2.0] [REST API] - Authentication Failed while using Azure AD Bearer Token, to return list of containers [Azure Blob] [Azure AD OAuth 2.0] [REST API] 在Azure中调用Web API时承载令牌不起作用 - Bearer token not working when calling web api in Azure .Net 客户端应用程序 Azure AD 身份验证 Cookie 身份验证然后 Bearer token 调用下游 API - .Net Client App Azure AD Authentication Cookie Authentication And then Bearer token to call downstream API 使用 MSAL.js 和 Azure Active Directory - 如何将身份验证令牌传递给承载策略 - Securing REST API Calls in SPAs using MSAL.js with Azure Active Directory - How to Pass Authentication Token to Bearer Strategy Azure oAuth 使用用户管理身份检索令牌 - Azure oAuth token retrieval with user managed identity 来自非 Azure VM 的托管身份验证 - Managed Identity Authentication from non Azure VM 使用 Azure 管理 API 进行身份验证 - Authentication with Azure Management API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM