Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
jornk
Contributor II
Contributor II

Authentication for Qlik .NET SDK

Hi,

I'm trying to authenticate using the Location interface from the Qlik .NET SDK. Location.IsAlive() returns False, and I can't figure out what I'm doing wrong. The communication are sent from one server over to the Qlik server. And on the Qlik server the port 4747 is opened for the request server's IP.

Any idea of what I'm doing wrong?

Here's my C# code example:

Uri uri = new("https://myQlikSenseServer.myDomain.com:4747");
ILocation location = Location.FromUri(uri);
X509Store store = new(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCol = new();
foreach (X509Certificate2 c in store.Certificates)
{
	if (c.Thumbprint == "myThumbprint")
	{
		certCol.Add(c);
	}
}
location.AsDirectConnection("myDomain", "myUser", certificateCollection: certCol);
Console.WriteLine(location.IsAlive().ToString());
/* location.IsAlive() writes: False */

 

3 Replies
Øystein_Kolsrud
Employee
Employee

I have two possible suggestions:

The first one is that you might be using a self-signed certificate and simply need to add the certificateValidation option to your call like this:

location.AsDirectConnection("myDomain", "myUser", certificateValidation: true,  certificateCollection: certCol);

The second is that you might be picking up the wrong certificate (or no certificate?) from the store. If you have installed it on your local machine, then you should be able to do like this instead:

var certCol = CertificateManager.LoadCertificateFromStore();

If none of those two help, then I suggest you use replace your call to location.IsAlive() with location.Hub(). That will give you a stack trace that hopefully provides you with some further clues as to what is going wrong.

jornk
Contributor II
Contributor II
Author

So when I try to use CertificateManager.LoadCertificateFromStore() I get the stacktrace below.

Is there a specific store the certificated should be imported to?

{
  "status": 500,
  "title": "Internal Server Error",
  "message": "No certificate with name \"QlikClient\" found in store.",
  "stackTrace": "Qlik.Engine.Communication.CertificateManager+CertificatesNotFoundInStoreException: No certificate with name \"QlikClient\" found in store.\r\n   at Qlik.Engine.Communication.CertificateManager.LoadCertificateFromStore()\r\n   at INSIGHT.Application.Services.Qlik.HelperService.QlikSDKTest()\r\n   at INSIGHT.Application.Services.Qlik.CrudService.QlikSDKTest()\r\n   at INSIGHT.Application.Services.Qlik.BackendService.QlikSDKTest()\r\n   at INSIGHT.Application.Controllers.QlikController.QlikSDKTest()\r\n   at lambda_method1555(Closure , Object , Object[] )\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\r\n   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n   at BIF.Web.App.AppTracking.Invoke(HttpContext context) in C:\\.bitbucket\\core\\ffr\\BIF.Web.App\\AppTracking.cs:line 56\r\n   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.CspMiddleware.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)\r\n   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)\r\n   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)\r\n   at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext)\r\n   at Microsoft.AspNetCore.OData.Routing.ODataRouteDebugMiddleware.Invoke(HttpContext context)\r\n   at BIF.Web.App.AppSwagger.Invoke(HttpContext context) in C:\\.bitbucket\\core\\ffr\\BIF.Web.App\\AppSwagger.cs:line 67\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n   at Microsoft.AspNetCore.OData.Batch.ODataBatchMiddleware.Invoke(HttpContext context)\r\n   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)",
  "traceId": "8008f7ca-0000-dd00-b63f-84710c7967bb",
  "requestId": "00-aea6dc0a26548c45bf6747ffc5228d0e-2919127fcb471e40-00"
}

 

Øystein_Kolsrud
Employee
Employee

I'm not sure about the store, but I'll guess that depends on how the certs were installed. But are you sure the certificates are there? And if you are, are you running the program with a user who can access it?

I'm afraid I don't know much about asp.net, but I know that sometimes you'll need to specify a X509KeyStorageFlags argument to ensure that the certificates are handled correctly:

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509keysto...