Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jmikhail
Contributor
Contributor

Impersonate on Qlik Cloud using jwt on .Net SDK

Hello,

I am using Qlik Cloud and Iam trying to impersonate with a different user than the current user using jwt session, I got it to work perfectly with the Rest Apis. however, I still need to do the same using the .Net SDK.

here is how I tried to impersonate using the jwt token that I used with rest api

qcsLocation = QcsLocation.FromUri(mQSenseURL);
qcsLocation.AsJwt(JwtToken);

And I tried also with:

mNETlocation = Location.FromUri(mQSenseURL);
mNETlocation.VirtualProxyPath = "jwt-session";
mNETlocation.AsJwtViaProxy(JwtToken);

Not sure what I am missing, can you help me to get it work? 

Labels (2)
1 Solution

Accepted Solutions
Øystein_Kolsrud
Employee
Employee

If you're doing both REST access and WebSocket access in the same project, then it's worth noting that you can't use the same JWT for authentication twice. You either have to use a new one for each, or connect using existing session for the second one. As example (if you use the package https://www.nuget.org/packages/QlikSenseRestClient/ for REST access), then this won't work because the JWT has already been "expended" when the connection to the app is attempted:

var restClient = new RestClient(url);
restClient.AsJsonWebTokenViaQcs(jwt);
Console.WriteLine(restClient.Get<JToken>("/api/v1/users/me"));

var location = QcsLocation.FromUri(url);
location.AsJwt(jwt);
using (var app = location.App(appId))
{
    Console.WriteLine(app.GetAppProperties().Title);
}

But this will as it reuses the session from the rest access:

var restClient = new RestClient(url);
restClient.AsJsonWebTokenViaQcs(jwt);
Console.WriteLine(restClient.Get<JToken>("/api/v1/users/me"));
            
var info = restClient.QcsSessionInfo;
            
var location = QcsLocation.FromUri(url);
location.AsExistingSession(info.EasSid,info.EasSidSig, info.SessionToken);
using (var app = location.App(appId))
{
    Console.WriteLine(app.GetAppProperties().Title);
}

View solution in original post

1 Reply
Øystein_Kolsrud
Employee
Employee

If you're doing both REST access and WebSocket access in the same project, then it's worth noting that you can't use the same JWT for authentication twice. You either have to use a new one for each, or connect using existing session for the second one. As example (if you use the package https://www.nuget.org/packages/QlikSenseRestClient/ for REST access), then this won't work because the JWT has already been "expended" when the connection to the app is attempted:

var restClient = new RestClient(url);
restClient.AsJsonWebTokenViaQcs(jwt);
Console.WriteLine(restClient.Get<JToken>("/api/v1/users/me"));

var location = QcsLocation.FromUri(url);
location.AsJwt(jwt);
using (var app = location.App(appId))
{
    Console.WriteLine(app.GetAppProperties().Title);
}

But this will as it reuses the session from the rest access:

var restClient = new RestClient(url);
restClient.AsJsonWebTokenViaQcs(jwt);
Console.WriteLine(restClient.Get<JToken>("/api/v1/users/me"));
            
var info = restClient.QcsSessionInfo;
            
var location = QcsLocation.FromUri(url);
location.AsExistingSession(info.EasSid,info.EasSidSig, info.SessionToken);
using (var app = location.App(appId))
{
    Console.WriteLine(app.GetAppProperties().Title);
}