The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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...

Parents
  • 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.

Reply Children
  • 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.

  • 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.