Hello everyone, I have created a simple .net dll in SnapDevelop and used 'Tools - > .Net dll importer to import it into a non visual object in PowerBuilder. The c# code is below.
The code to call this in PowerBuilder is:
nvo_useraccesstokenutil n_gettoken
String ls_token
n_gettoken = CREATE nvo_useraccesstokenutil
SetNull(ls_token)
ls_token = n_gettoken.of_gettokenforapi("05c5c963-c839-4c9e-b5c1-b51b3799ac37", "6a4ae5f6-00f8-4571-ab73-aa9f9d2b1fea", &
"api://6a4ae5f6-00f8-4571-ab73-aa9f9d2b1fea/.default", "d2e65c6d-0f75-4fa1-95c2-379656390fcf", "http://localhost:12345/EAS")
When I create a test c# app in snapdevelop it works fine. From PowerBuilder it never gets to:
return "5"; in the code below. Just wondering if anyone has any ideas. Thanks in advance.
c# code
using Microsoft.Identity.Client;
using System.Diagnostics;
namespace Wcb.Common.PowerServer
{
public class UserAccessTokenUtil
{
public string GetTokenForApi(string tenant, string apiClientId, string apiScope, string appClientId, string redirectUrl)
{
//Console.WriteLine("Hello, World!");
//return "Return value from call";
var scopes = new List<string> { apiScope };
var publicClientApp = PublicClientApplicationBuilder.Create(appClientId).WithRedirectUri(redirectUrl).WithAuthority(AzureCloudInstance.AzurePublic, tenant).Build();
AuthenticationResult result;
var accounts = publicClientApp.GetAccountsAsync().Result;
if (accounts.Any())
{
return "2";
result = publicClientApp.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.ExecuteAsync().Result;
return "3";
}
else
{
result = publicClientApp.AcquireTokenByIntegratedWindowsAuth(scopes) .ExecuteAsync().Result;
return "5";
}
return $"Parameter values: tenant={tenant}, apiClientId={apiClientId}, apiScope={apiScope}, appClientId={appClientId}, redirectUrl={redirectUrl}";
}
}
}