Hi @Alan ,
Thanks for reaching out.
I understand you are trying to call Graph API endpoint using Blazor WASM project but getting "InvalidAuthenticationToken" error. Although you are able to use the endpoint successfully using Graph Explorer.
Graph Explorer is the tool provided by Microsoft to explore Graph API endpoints by allowing you to sign into your tenant directly. It has inbuilt access token provided to you to easily access the Graph API. However, to call all the Graph API endpoints using postman or within the code require the valid access token with required permissions to call the Microsoft Graph.
You need to call IAuthenticationProvider to authenticate the request and request Access token based on the request and this access token need to pass as bearer token in Authorization Header to call the Graph API endpoint as below:
private class GraphAuthenticationProvider : IAuthenticationProvider
{
public GraphAuthenticationProvider(IAccessTokenProvider provider)
{
Provider = provider;
}
public IAccessTokenProvider Provider { get; }
public async Task AuthenticateRequestAsync(HttpRequestMessage request)
{
var result = await Provider.RequestAccessToken(new AccessTokenRequestOptions()
{
Scopes = new[] { "https://graph.microsoft.com/User.Read" }
});
if (result.TryGetToken(out var token))
{
request.Headers.Authorization ??= new AuthenticationHeaderValue("Bearer", token.Value);
}
}
}
Reference :https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/graph-api?view=aspnetcore-6.0
Hope this will help.
Thanks,
Shweta
Please remember to "Accept Answer" if answer helped you.
I see that I have to download Microsoft.Graph.Beta but I can't find it in Nuget.
You can install nuget package using dotnet add package Microsoft.Graph.Beta --version 5.10.0-preview
Find the reference to use beta endpoint with dotnet SDK : https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet
The beta endpoint APIs are currently in preview and are not recommended to use in production.
Thanks,
Shweta