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

  • Hi,
    I am also trying to login to ProjectWise using Bentley IMS. I am not getting any loginToken as "aaApi_GetRelyingPartyIdentifier(serverName, ref relyingParty)" returns false. Hence, login is unsuccessful. Please help!

    Thanks.

  • My apologies for the delay, but I have a working sample up on github now.  https://github.com/DanWilliamsAtBentleyDotCom/Sample-Login-With-Security-Token 

    Please give it a try and let me know if it worked or what specific problems you are having when you run a debugger against the code.

    I used Visual Studio 2015, ProjectWise  v10.00.03.140, ProjectWise SDK v10.00.03.140, CONNECTION Client v10.00.18.13 and tested against two different datasources using two different IMS accounts.

    Oh, and I'd like to point out that the cleverness of the class ConnectionClientToken.cs, is all Dave Brumbaugh's work!  If you haven't done so yet, you can get his MostOfDavesClasses.cs (and supporting files) at https://github.com/DaveBrumbaugh

    Answer Verified By: Matthew Howdill 

Reply Children