RestClient and SSO, is it supposed to work?

Interesting thread…

@HLalumiere I am kinda lost on this. Are you calling a function from a form customization within the smart client?

Yes…

Kinetic form?

Run your session objects through this, and let’s see it.
This is only single level and very simple.
May or may not let us know what we need to see.

  //For BPM, Function, etc
  //Single Level Object Walker
  Func<object, int, string> GetObjectProperties = (_obj, padding) =>
  {

    string _nl = Environment.NewLine;
    //string tab = "\t";

    string retValue = "";
    foreach (var prop in _obj.GetType().GetProperties())
    {
      try
      {
        retValue += prop.Name.PadRight(padding);

        try
        {
          retValue += prop.GetValue(_obj, null).ToString();
        }
        catch {}
        
      }
      catch {}
      retValue += _nl;
    }
    return retValue;
  };



  //For Classic UI Customization
  //Single Level Object Walker
  string GetObjectProperties(object _obj, int padding = 30)
  {

    string _nl = Environment.NewLine;
    //string tab = "\t";

    string retValue = "";
    foreach (var prop in _obj.GetType().GetProperties())
    {
      try
      {
        retValue += prop.Name.PadRight(padding);

        try
        {
          retValue += prop.GetValue(_obj, null).ToString();
        }
        catch {}
        
      }
      catch {}
      retValue += _nl;
    }
    return retValue;
  }

We use Azure AD and this is what we use to generate proper Auth

using System.Reflection;

public bool SetupEpicorRest(string apiKey)
    {
        try
        {
            
            string username,password, token;
			EpicorRest.Company = session.CompanyID;

			Assembly sm = Assembly.LoadFrom("Epicor.ServiceModel.dll");  // Kinetic Uplift
			object authClass = sm.CreateInstance("Epicor.ServiceModel.Wcf.Security.AuthenticationWcf");  // Kinetic Uplift
			Type smType = authClass.GetType();  // Kinetic Uplift
			BindingFlags bf = BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public;  // Kinetic Uplift
			MethodInfo mi = smType.GetMethod("IsWindows", bf);  // Kinetic Uplift
			object[] invParams = new object[1]{AppSettingsHandler.AuthenticationMode};  // Kinetic Uplift
			bool isWindows = (bool)mi.Invoke(authClass,invParams);  // Kinetic Uplift
			

            var accessTokenFunc = typeof(Ice.Core.Session).GetProperty("GetAccessTokenFunc", BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public).GetValue(session) as Func<bool,string>;
            if(accessTokenFunc !=null)
            {
                token = accessTokenFunc(false); //Gets Bearer Token
            }
			else if(isWindows) // Kinetic Uplift
            {
                username = Environment.UserName; //Uses Windows Auth
                password = "";
            }
            else
            {
				// Pulls username and password
                object clientCreds = typeof(Ice.Core.Session).GetProperty("ClientCredentials", BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public).GetValue(session);
                if(clientCreds!=null)
                {
                    object clientCredsUname = clientCreds.GetType().GetProperty("UserName").GetValue(clientCreds);
                    username =clientCredsUname.GetType().GetProperty("UserName").GetValue(clientCredsUname) as String;
                    password =clientCredsUname.GetType().GetProperty("Password").GetValue(clientCredsUname) as String;
                }
            }
            Console.WriteLine($"user: {username} pwd:{password} token:{token}");
            return true;
        }
        catch(Exception ex)
        {
            return false;
        }
    }
5 Likes

Appreciate the suggestion, but as mentioned the source code to RestClientBuilder makes it pretty clear it never was setup to work with AzureAD from a session object… And anyway I’m out of time for this issue, customer will embed username and password in the customization and we’ll leave it there…

The code I just posted should get you the token from the current session which is a little less crappy.

2 Likes

Thanks Jose, I will keep it in mind… But between the debugging time, the week lost to the support black hole, and that it’s Friday 13th…

GIF by SkySlope

Thanks Jose.

1 Like

Never had to use that before, but I would have assumed that would have been available for direct
reference. Guess not.

Or did you just make that so you could use it anywhere?

^ that also its easier to reflect a type from the Dll than it is from a reference class. I would have had to back my way into the parent Assembly of a referenced class seemed like more work than just re-loading the assembly by name since its in the CWD anways.

This class is private internal
Epicor.ServiceModel.Wcf.Security.AuthenticationWcf

So I had to instantiate it from the assembly reference always :unamused:

2 Likes

I’m pretty sure there is a secrets management library/table Epicor has you can use to store those creds.

You sneaky beautiful bastard.

I can’t wait to understand this part of Epicor. I get it from like high high high level, but I can’t wait to actually build something that uses these methods.

season 2 shrug GIF by Fox TV

Hugo, I swallowed the red pill a long time ago. Still training and learning though.

no you dont understand the sandlot GIF

1 Like

Hahaha

I understand the code, and what he did.
I still don’t understand how he got there.

1 Like