You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Graph API从.NET 6 Azure Function获取Microsoft Learn认证遇401错误

问题:通过Graph API获取Microsoft Learn认证列表遇401未授权错误

我尝试通过Graph API从我的Microsoft Learn个人资料中获取Azure认证列表。

生成令牌的Azure Functions代码

string[] scopes = new string[] { $"{clientId}/.default" };

IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithTenantId(tenantId)
    .WithClientSecret(clientSecret)
    .Build();

AuthenticationResult authResult = await confidentialClientApplication.AcquireTokenForClient(scopes).ExecuteAsync();

string authToken = authResult.AccessToken;
Console.WriteLine("Access token: {0}", authToken);

操作步骤

  • 在Azure AD中注册应用,配置以下权限:
    • MicrosoftGraph - User.Read
    • MicrosoftGraph - Directory.Read.All
  • 为注册的应用生成客户端密钥(Client Secret)
  • 基于.NET 6开发Azure Function:
    • 使用上述AAD应用注册生成Bearer令牌
    • 在请求头中携带Bearer令牌调用Microsoft Graph API
    • API端点:https://graph.microsoft.com/beta/users/kuldeepsingh/profile/certifications

执行后遇到401未授权错误,寻求解决帮助。

已尝试方案1

  • 注册类型为“仅限此组织目录中的帐户”的应用,配置以下权限:
    • MicrosoftGraph - User.Read
    • MicrosoftGraph - User.Read.All
  • 使用以下范围生成令牌:
string[] scopes = new string[] { $"https://graph.microsoft.com/.default" };
  • 触发错误信息:

"/me请求仅在委派身份验证流中有效。"

重要更新说明

目前Microsoft Learn个人资料中的认证与/me/profile/certifications之间无同步机制,因此技术上无法通过Graph API获取Microsoft Learn认证。


内容的提问来源于stack exchange,提问作者Kuldeep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 10:42:16