79444699

Date: 2025-02-17 07:36:13
Score: 1.5
Natty:
Report link

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;

}

reference link

If you found any solution rather than this let me know.

Reasons:
  • Blacklisted phrase (1.5): any solution
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Sanju Chilukuri