kolsrud / qlik_rest_sdk

SDK for accessing the Qlik Sense REST APIs
MIT License
20 stars 4 forks source link

Authentication error for qps endpoints #22

Closed sprudel79 closed 1 year ago

sprudel79 commented 1 year ago

Hi, thanks for the efforts spent into this project. I've been using this library for several years now and it was working without any issues. Recently (after having upgraded to version 1.14.0) I had noticed an issue when trying to call a qps endpoint of our QlikServer. To prepare the client I am using a code similar to this:

var qpsRestClient = new RestClient("baseUrl");
qpsRestClient.AsDirectConnection("ServiceUserDirectory", "ServiceUserId", QPSPort = 4243, false, serverCertificateCollection); 

Within the "AsDirectConnection" method the BaseUri gets extracted like this:

 var uriBuilder = new UriBuilder(BaseUri) { Port = port };
 BaseUri = uriBuilder.Uri;

Since I am working with "qps" the port passed is 4243 and not 4242, so the BaseUri also gets the port 4243. Before calling any endpoint an authentication logic takes place:

private async Task CollectCookieAsync()
{
    RestClientDebugConsole?.Log($"Authenticating (calling GET /qrs/about)");
    var client = GetClient();
    await LogReceive(client.GetStringAsync(BaseUri.Append("/qrs/about"))).ConfigureAwait(false);
    RestClientDebugConsole?.Log($"Authentication complete.");
}

The problem here is that we try to call the /qrs/about endpoint but we are in the qps context (port=4243). Since the GET request to this endpoint returns a 503 error, the authentication fails and I cannot call any qps endpoint. Thanks in advance for any feedback on that issue.

kolsrud commented 1 year ago

Interesting case! I'll have a look at it!

kolsrud commented 1 year ago

Hi! I've just published v1.14.1 that contains a fix for this. There's no need to do that authentication procedure when using direct connections, so I simply removed the step in those cases. So, simple fix. Please try it out and see if it does the trick!

kolsrud commented 1 year ago

By the way, which version were you upgrading from? I think perhaps this issue became a problem in v1.12.0 so I'm guessing your coming from a release earlier than that.

sprudel79 commented 1 year ago

Many thanks @kolsrud for your efforts spent into this issue. I was working on a project that hasn't been touched for a few years, so I am not sure anymore (if it is required I can check the Git history) which version I was using back in the days but it was definitely 2020 or even older. I was able to verify the setup with the latest v1.14.1 and it works again, thank you very much! Issue can be closed :-)

kolsrud commented 1 year ago

OK, thanks for confirming! It's not that important to know which version you upgraded from. I was just curious. Glad to hear it works!