gpt4 book ai didi

c# - Azure 函数 - 从 DefaultCredentials\Managed Identity 获取 token

转载 作者:行者123 更新时间:2023-12-05 04:26:40 25 4
gpt4 key购买 nike

我正在使用一个 Azure 函数,该函数需要使用 JWT 对 API/APP 服务进行身份验证。

我已经查看了很多示例,并认为这是最合适的

public string GenerateToken()
{
var credential = new Azure.Identity.DefaultAzureCredential();
var token = credential.GetToken(new Azure.Core.TokenRequestContext(new[] { "https://management.azure.com/" }));
return token.Token;
}

示例从这里诞生 https://learn.microsoft.com/en-us/dotnet/api/azure.core.tokencredential?view=azure-dotnet

我也尝试过使用这个https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-c

在这里,这与我的问题类似,但因为它没有使用托管身份,所以我工作的公司说这是不行的。 Create azure bearer token from azure function

我认为问题在于范围,但我找不到进入我的应用服务的正确范围。

我还尝试了 api://、资源 url 等

非常感谢您提供的所有帮助。

最佳答案

Azure AD 允许您使用 .default作为检索主体已被授予的所有访问权限的范围。

对于您的情况,您可以通过 api://<commonly-api-client-id-uuid>/.default这将检索一个 token ,其中包含您的 Azure 函数的托管身份主体已在目标 API/应用程序上授予的所有角色

关于c# - Azure 函数 - 从 DefaultCredentials\Managed Identity 获取 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72992376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com