ProjectWise SDK - Bentley IMS Login

I need to use the ProjectWise SDK (not the pwps_dab module) to login using Bentley IMS authentication. The documentation indicates 'aaApi_LoginWithSecurityToken' is the function but I'm not sure how to acquire the 'security token'. Does anyone have a working example they can share? 

Parents
  • I mean to post some code for this, but here's a snippet that may help you, but it is in C#, so you man need to use MostOfDavesClasses.

    You can get that code with the link in this post:  https://communities.bentley.com/products/programming/projectwise_programming/m/mediagallery/273950 

    However that link doesn't demonstrate using IMS authenication.

    So here's the snippet:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    
    namespace SampleIMSConsole
    {
        class Program
        {
            [DllImport("c:\\program files\\bentley\\projectwise\\bin\\dmscli.dll", CharSet = CharSet.Unicode)]
            private static extern bool aaApi_LoginWithSecurityToken(string dataSource, string securityToken, bool asAdmin, string hostname, long[] productIds);
    
            // BOOL aaApi_GetRelyingPartyIdentifier(LPCWSTR pServerName, LPWSTR* ppRelyingPartyIdentifier )
            [DllImport("c:\\program files\\bentley\\projectwise\\bin\\dmscli.dll", CharSet = CharSet.Unicode)]
            private static extern bool aaApi_GetRelyingPartyIdentifier(string serverName, ref string relyingPartyIdentifier);
    
            static void Main(string[] args)
            {
                if (args.Length > 0)
                {
                    string _loginToken = ""; // MyLoginCommands.GetLoginToken(DatasourceName);
    
                    string relyingParty = "";
                    string serverName = args[0].Split(':')[0];
                    bool relyingPartySuccess = aaApi_GetRelyingPartyIdentifier(serverName, ref relyingParty);
    
                    // Contact the Connection Client and ask for the login token.
                    try
                    {
                        Bentley.Connect.Client.API.V1.ConnectClientAPI conn = new Bentley.Connect.Client.API.V1.ConnectClientAPI();
    
                        _loginToken = conn.GetSerializedDelegateSecurityToken(relyingParty);
                    }
                    catch (Exception ex)
                    {
                    }
    
                    if (aaApi_LoginWithSecurityToken(args[0], _loginToken, true, null, null))
                    {
                        Console.WriteLine(string.Format("Logged in OK to '{0}' with BentleyIMS.", args[0]));
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Error logging in to '{0}'", args[0]));
                    }
    
                }
            }
        }
    }
    

    HTHs

    Dan Williams
    Solution Consultant
    Bentley Systems, Incorporated
    Portland, OR, USA (Pacific Time UTC-08:00)

Reply
  • I mean to post some code for this, but here's a snippet that may help you, but it is in C#, so you man need to use MostOfDavesClasses.

    You can get that code with the link in this post:  https://communities.bentley.com/products/programming/projectwise_programming/m/mediagallery/273950 

    However that link doesn't demonstrate using IMS authenication.

    So here's the snippet:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    
    namespace SampleIMSConsole
    {
        class Program
        {
            [DllImport("c:\\program files\\bentley\\projectwise\\bin\\dmscli.dll", CharSet = CharSet.Unicode)]
            private static extern bool aaApi_LoginWithSecurityToken(string dataSource, string securityToken, bool asAdmin, string hostname, long[] productIds);
    
            // BOOL aaApi_GetRelyingPartyIdentifier(LPCWSTR pServerName, LPWSTR* ppRelyingPartyIdentifier )
            [DllImport("c:\\program files\\bentley\\projectwise\\bin\\dmscli.dll", CharSet = CharSet.Unicode)]
            private static extern bool aaApi_GetRelyingPartyIdentifier(string serverName, ref string relyingPartyIdentifier);
    
            static void Main(string[] args)
            {
                if (args.Length > 0)
                {
                    string _loginToken = ""; // MyLoginCommands.GetLoginToken(DatasourceName);
    
                    string relyingParty = "";
                    string serverName = args[0].Split(':')[0];
                    bool relyingPartySuccess = aaApi_GetRelyingPartyIdentifier(serverName, ref relyingParty);
    
                    // Contact the Connection Client and ask for the login token.
                    try
                    {
                        Bentley.Connect.Client.API.V1.ConnectClientAPI conn = new Bentley.Connect.Client.API.V1.ConnectClientAPI();
    
                        _loginToken = conn.GetSerializedDelegateSecurityToken(relyingParty);
                    }
                    catch (Exception ex)
                    {
                    }
    
                    if (aaApi_LoginWithSecurityToken(args[0], _loginToken, true, null, null))
                    {
                        Console.WriteLine(string.Format("Logged in OK to '{0}' with BentleyIMS.", args[0]));
                    }
                    else
                    {
                        Console.WriteLine(string.Format("Error logging in to '{0}'", args[0]));
                    }
    
                }
            }
        }
    }
    

    HTHs

    Dan Williams
    Solution Consultant
    Bentley Systems, Incorporated
    Portland, OR, USA (Pacific Time UTC-08:00)

Children