graph api InvalidAuthenticationToken

neeraj badalu 41 Reputation points
2022-03-10T07:22:34.287+00:00

Hi
We are using graph api to create appointment\event in exchange using below code which working fine with "microsoftonline.com" and "graph.microsoft.com" as below. our one client having domin "microsoftonline.us" and "graph.microsoft.us"

    Helper.Setting setting = Helper.ExchangeSetting.GetSetting(exchangeConfigName);  

            IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(setting.ClientIdGrpah)  
              .WithAuthority($"https://login.microsoftonline.com/{setting.TenantIdGraph}")  
              .WithRedirectUri(setting.PublicNotificationUrl)//("http://localhost")  
              .WithClientSecret(Helper.Cryptography.DecryptText(setting.ClientSecretGraph))  
              .Build();  
            string[] scopes = new string[] { "https://graph.microsoft.com/.default" };  

            AuthenticationResult authResult = await app.AcquireTokenForClient(scopes).ExecuteAsync().ConfigureAwait(false);  
           
            return authResult.AccessToken;    

To over come this cross domain issue we have change code to WithAuthority($"https://login.microsoftonline.us/{setting.TenantIdGraph}")
string[] scopes = new string[] { "https://graph.microsoft.us/.default" };
After code change we are getting token but when we try to create appointment\event we are getting below issue
Message: Access token validation failure. Invalid audience.
Inner error:
AdditionalData:
date: 2022-03-07T15:23:25
request-id: 53918c5f-6ba7-4869-984b-99e805d67aa1

Same permission has given on graph api (graph.microsoft.us)in azure which works for (graph.microsoft.com).
181727-image.png

Need your experts help

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-04-04T19:05:55.44+00:00

    Hi @neeraj badalu , if you're using the US Government L4 endpoint, please review this document and make sure everything is configured properly. As Carl mentioned, you need to make sure the SDK is referencing it and not another endpoint.

    Best,
    James

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.