gpt4 book ai didi

c# - 尝试获取用于访问自定义 api 的 token 时出现 MSAL 错误消息 AADSTS65005

转载 作者:行者123 更新时间:2023-11-30 16:43:19 25 4
gpt4 key购买 nike

我下载了下面的示例以从 MS Graph 获取访问 token ,效果很好。现在,我更改了代码以从自定义 Web API 获取 token 。在 apps.dev.microsoft.com 上,我注册了一个客户端应用程序和一个 API。

Client and server registration in AD

private static async Task<AuthenticationResult> GetToken()
{
const string clientId = "185adc28-7e72-4f07-a052-651755513825";

var clientApp = new PublicClientApplication(clientId);

AuthenticationResult result = null;

string[] scopes = new string[] { "api://f69953b0-2d7f-4523-a8df-01f216b55200/Test" };

try
{
result = await clientApp.AcquireTokenAsync(scopes, "", UIBehavior.SelectAccount, string.Empty);
}
catch (Exception x)
{
if (x.Message == "User canceled authentication")
{

}
return null;
}
return result;
}

当我运行代码时,我通过对话框登录到 AD,并在调试器中得到以下异常:

Error: Invalid client Message = "AADSTS65005: The application'CoreWebAPIAzureADClient' asked for scope 'offline_access' thatdoesn't exist on the resource. Contact the app vendor.\r\nTrace ID:56a4b5ad-8ca1-4c41-b961-c74d84911300\r\nCorrelation ID:a4350378-b802-4364-8464-c6fdf105cbf1\r...

Error message

帮助感谢尝试了几天......

最佳答案

对于仍然遇到此问题的人,请阅读以下内容:

https://www.andrew-best.com/posts/please-sir-can-i-have-some-auth/

在这个人反射(reflect)了你所有的挫败感之后,你会感觉好多了,除了他解决了问题......

如果使用 adal.js,对于您的范围,您需要使用

const tokenRequest = {
scopes: ["https://management.azure.com/user_impersonation"]
};

我花了一周时间

const tokenRequest = {
scopes: ["user_impersonation"]
};

.. 因为这是图形 API 范围采用的格式

关于c# - 尝试获取用于访问自定义 api 的 token 时出现 MSAL 错误消息 AADSTS65005,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45254631/

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