- David Pylatuk
- PowerBuilder
- Tuesday, 20 February 2024 07:14 PM UTC
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}";
}
}
}
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.