I’m experienced the same issue. The application access token isn’t working and is returning a 401 error. Once try with the client access token by modifying the code like this.
public async Task<string> GetAccessToken()
{
var tenantId = Configuration.TenantId;
var clientId = Configuration.ClientId;
var authority = $"https://login.microsoftonline.com/{tenantId}";
var scopes = new string[] { "https://domain.sharepoint.com/.default" };
var cca = PublicClientApplicationBuilder.Create(clientId)
.WithRedirectUri("http://localhost")
.WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
.Build();
var result = await cca.AcquireTokenInteractive(scopes).ExecuteAsync();
return _authToken = result.AccessToken;
}
return _authToken;
}
If you found any solution rather than this let me know.