在另一个服务中使用其托管身份对服务调用者进行身份验证

问题描述

在另一个App Service / .NET Core WebAPI中验证呼叫者(具有托管身份的App Service / .NET Core WebAPI,而不代表登录用户的身份)的最新技术是什么(还有自己的托管身份)?我想使用Azure API管理隐藏被调用的服务和尽可能少的键。

编辑:

API :应用服务Azure授权/ Active Directory设置:

enter image description here

API应用注册详细信息:

enter image description here

应用注册/ API应用/身份验证:

  • 隐式授予-仅检查ID令牌

  • 支持的帐户类型-单租户

enter image description here

应用注册/ API应用/公开API:

enter image description here

当我尝试添加客户端应用程序时,出现了以下问题({d1d是我的客户端应用程序服务托管ID 的结尾):

enter image description here

解决方法

您不需要API的托管身份,任何app registration都可以。设置其application id uri并使用Azure.Identity nuget package来获得具有以下内容的令牌:

var managedIdentityCredential = new ManagedIdentityCredential();
var scopes = new []{"{your api application id uri}/.default"}; // E.G: api://3a768fed-640b-420c-8b33-39c701c55199/.default
var accessToken = (await managedIdentityCredential.GetTokenAsync(new Azure.Core.TokenRequestContext(scopes))).Token;

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...