【发布时间】:2020-06-23 17:53:38
【问题描述】:
我正在尝试根据在 Blazor 客户端应用程序中检索到的访问令牌从 Microsoft 的 Graph API 检索用户组。
Index.razor.cs 部分。
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using System;
using System.Threading.Tasks;
using Microsoft.Graph;
using System.Net.Http.Headers;
using System.Linq;
namespace blazorapp.Pages
{
public partial class Index
{
[Inject]
IAccessTokenProvider TokenProvider { get; set; }
protected override async Task OnInitializedAsync()
{
var tokenResult = await TokenProvider.RequestAccessToken(
new AccessTokenRequestOptions
{
Scopes = new[] { "https://graph.microsoft.com/GroupMember.Read.All" }
});
if (tokenResult.TryGetToken(out var token))
{
Console.WriteLine(token.Value);
try
{
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("Bearer", token.Value);
return Task.FromResult(0);
}));
var securityEnabledOnly = true;
var groupsRequest = await graphServiceClient
.Me
.GetMemberGroups(securityEnabledOnly)
.Request()
.PostAsync();
} catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
}
它可以很好地返回令牌,并且当在 jwt.ms 或 postman 中使用时,它会很好地返回。但是在浏览器中我得到了
“不支持属性代理。”从我的 catch 块内的控制台日志中。我的代码中是否存在可能导致此问题的明显错误?
【问题讨论】:
-
能否分享一下你使用代理的代码sn-p
标签: c# azure-active-directory microsoft-graph-api blazor