Using LogInAsUser Method

Hello !

I'm trying to allow an excel document to have admin autorisations so the document can do things the user can't.

In order to do that, I'm trying to connect to my M-Files vault with an admin account when I open the document (as i would with the current user session) :

I define a MFiles Client Application Object :

Dim oClientApp As Object
Set oClientApp = CreateObject("MFilesAPI.MFilesClientApplication")

Then I define my vault connection :

Dim oVaultConnection As Object
Set oVaultConnection = CreateObject("MFilesAPI.VaultConnection")
Set oVaultConnection = oClientApp.GetVaultConnection("Myvault")

And finally, I log in with the correct credentials :

Dim oVault As Object
Set oVault = CreateObject("MFilesAPI.Vault")
Set oVault = oVaultConnection.LogInAsUser(MFAuthTypeSpecificMFilesUser, "Username", "Password")

With Username and Password being the actual username and the actual password.

However, when I run the code, I get the following error :

"Automation error
Indicator proposed incorrect"

I've been trying every possible method and parameters for days and I'm out of options.

Does anyone have a clue on what to do ? The API isn't really helping...

  • How is the vault connection defined in the client?  Is it set to use (automatic) Windows auth?  What does "oVaultConnection.IsLoggedIn" return?

    My suspicion is that the connection is already made with the current user's details, so it doesn't like you attempting to re-authenticate.  Remember that you're not creating a new connection here, you're re-using whatever the user has configured (and/or is actively using).  You may instead need to switch to a server connection instead, whereby you can control the exact way in which the connection and authentication are made.

    Regards,

    Craig.

  • Hello ! Thanks for the quick reply !

    The vault connection is defined as "MFAuthTypeLoggedOnWindowsUser". "oVaultConnection.IsLoggedIn" return "True". I thought it meant that "oVaultConnection" had established a connection but still had to log in with credentials which was usually made somehow though the "BindToVault" Method. Obviously, I was wrong.

    So I'm now trying to establish a server connection, but I've never done it before, and once again, the API isn't of much help. I first declare : 

    Dim oServerApp As Object
    Set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")

    And then I try to connect to the server using the Connect Method but I don't know if I have to declare an object first or if I just can connect like that. I've tried with the default settings I've seen on the API with no success : same error as before.

    oMFServerConnection = oServerApp.Connect(MFAuthTypeSpecificMFilesUser, "Username", "Password", "ncacn_ip_tcp", "localhost", 2266, "", False)

    Can you tell me what I'm missing ?

  • Have you seen the examples here? Connecting and Authenticating (m-files.com)

    When connecting using the client mode you effectively "inherit" all of the connection details that have already been configured.  When using the server mode you need to explicitly provide both the server details and the credentials to connect with.

    Regards,

    Craig.

  • As Craig said, you need to give all the necessary data to get it. Here's a working example of VBScript

    Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
    oServerApp.Connect MFAuthTypeSpecificWindowsUser, MFilesAdmin, MFilesAdminPass, MFilesBase, MFProtocol , MFServerAddress , MFServerPort
    Set oVault = oServerApp.LogInToVault(VaultGUID)	

  • I have seen the examples and i've tried them before. That's actually what I used as a model. But I'm not sure if I find them very helpful.

    First I have to name the line "oServerApp.Connect" as something or else I can't run the code, and then, even if I don't specify any of the parameters to get the default connection (like shown in the model), I still get the same error (might be dumb to specify nothing but at this point I don't know what works and what doesn't.). Anyway, I defined all the correct server details and credentials, as they are in my previous message, and I do get the same error.

    Since I don't know how to connect via the server, I can't find what I'm doing wrong. Do you have any ideas ?

    Thanks in advance,

    Bob.

  • Do you have the full error message, before translation, that you get when using the server connection mode?  And the exact code you're using to get this error.

    In general terms there's nothing obviously incorrect in what you've posted.  I'm wondering whether it's something as simple as the fact that you don't have "MFAuthTypeSpecificMFilesUser" declared anywhere, so it's passing some sort of invalid value (Nothing?  Been a while since I used VBA).  Are you using Option Explicit?  These are enumeration values and, if they're not available, you will need to pass the specific number instead (e.g. 3, from M-Files API - MFAuthType Enumeration).

    If you're still struggling then perhaps either provide us with a copy of the file so that we can see it in-situ, or maybe reach out to your reseller?  They may be able to offer a Teams call or something to see exactly what you're doing and assist.

    Regards,

    Craig.

  • Thanks for the reply !

    It is close to what I wrote and that helps a lot !

    I have several questions if you don't mind :

    1. Do I have to connect as "MFAuthTypeSpecificWindowsUser" if the default user's connection is via ""MFAuthTypeSpecificWindowsUser"" or can I still connect via "MFAuthTypeSpecificMFilesUser" ?
    2. What is "MFilesBase" ? Is it the domain ? If yes, where to I get it's value ?

    Thanks in advance,

    Bob.

  • Here is the code (I've hidden credentials, just to be safe) :

    And here is the error :

    As for "MFAuthTypeSpecificMFilesUser", I've tried to replace it by the Windows equivalent, and juging by the color in the code, I'd say it works. I've tried with number 2 for the windows login and I still get the same error.

  • Oh the header did sound great - login as admin and then login in "as a user" in meaning of using the same rights just to have a look what the user sees and is allowed to do.

    Otherwise you have always to force yourself not to forget the tests with limited rights because it normally all works fine if you have sysadmin rights. :)

  • Hello  Falk,

    No, I only intend to give a document its own autorisations so it's easier to code interactions with M-Files. I get errors way too often because of the lack of autorisations from the user. To solve that, I can either give users full autorisations everywhere (which I don't really like or can do) or only when using the document.

    I haven't manage to make it work yet since I've been away for a few days but I'm sure it's a matter of server parameters.