I’m working on a module that has a lot of data exposed as a REST API and I’m currently using HTTP Basic Auth against an Ignition user source for authentication. I’d like to add the ability to use these API endpoints from Perspective, and would like to use the Session ID (as the user would already be authenticated).
I’ve played with the following line of code and browsing around using breakpoints:
List<ClientReqSession> sessions = gatewayContext.getGatewaySessionManager().findSessions();
but I’m struggling to find a property that matches the Perspective SessionID session property that I see in my designer.
You can get the current sessionId with
InternalSession.SESSION.get().getSession().getSessionId()
This requires you depend on the Perspective module, first of all, and second that ThreadLocal is only populated if you make this call within the context of a Perspective request.
I think you’ll have to depend on Perspective regardless, though. Try this:
Get the Perspective GatewayHook
by calling com.inductiveautomation.perspective.gateway.GatewayHook.get
.
Get the PerspectiveContext
by calling GatewayHook::getContext
.
Get the PerspectiveSessionMonitor
by calling PerspectiveContext::getSessionMonitor
.
Try looking up a session id using PerspectiveSessionMonitor::findSession
.
Good luck
2 Likes
Got it working - thanks for your help @Kevin.Herron!
1 Like