79388414

Date: 2025-01-26 11:21:10
Score: 1
Natty:
Report link

I also got same issue. For me user access token worked. rather than app access token.

public async Task<string> GetAccessToken()
    {
        if (_authToken == null)
        {
            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;

    }

But don't forget to add redirect URL in Azure. under Home>>App registartions>>App>>Authentication.

Azure Redirect URI

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Sanju Chilukuri