Connect to BC web service from a windows console application using Oauth 2 for user authorization

Faran123Faran123 Member Posts: 10
Hi community,
I am using following code to access business central web service using Oauth2 authentication from C# console application, the access token generated successfully but I'm unbale to access BC web service due to invalid credentials, problem is that the access token generated from below code is rather shorter (1500) characters but from postman it is around (1700) characters.
Can anyone help me in this regard. I copied the following code from following link:

static void Main(string[] args)
// Get access token from Azure AD. This will show the login dialog.
var authenticationContext = new AuthenticationContext(""+AadTenantId, false);
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(ServerAppIdUri, ClientId, new Uri(ClientRedirectUrl), new PlatformParameters(PromptBehavior.SelectAccount)).GetAwaiter().GetResult();
// Connect to the Business Central OData web service
var nav = new NAV.NAV(new Uri("'CRONUS Danmark A/S')"));
nav.BuildingRequest += (sender, eventArgs) => eventArgs.Headers.Add("Authorization", authenticationResult.CreateAuthorizationHeader());

// Retrieve and return a list of the customers
foreach (var customer in nav.AccountantPortalActivityCues)
Console.WriteLine("Found customer: " + customer.CurrencySymbol);
Sign In or Register to comment.