Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
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);
}
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);
}