# REST API Using Perspective SessionID to Authenticate

**URL:** <https://forum.inductiveautomation.com/t/rest-api-using-perspective-sessionid-to-authenticate/49053>\
**Category:** Module Development\
**Created:** [July 21, 2021, 7:52pm UTC](https://forum.inductiveautomation.com/t/rest-api-using-perspective-sessionid-to-authenticate/49053 "2021-07-21T19:52:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [July 21, 2021, 7:52pm UTC](https://forum.inductiveautomation.com/t/rest-api-using-perspective-sessionid-to-authenticate/49053/1 "2021-07-21T19:52:47Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [July 21, 2021, 7:57pm UTC](https://forum.inductiveautomation.com/t/rest-api-using-perspective-sessionid-to-authenticate/49053/2 "2021-07-21T19:57:05Z")

</div>

You can get the current sessionId with

InternalSession.SESSION.get().getSession().getSessionId()

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 21, 2021, 8:02pm UTC](https://forum.inductiveautomation.com/t/rest-api-using-perspective-sessionid-to-authenticate/49053/3 "2021-07-21T20:02:07Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![cody.tamaki](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@cody.tamaki](https://forum.inductiveautomation.com/u/cody.tamaki)\
**Post date:** [July 21, 2021, 10:44pm UTC](https://forum.inductiveautomation.com/t/rest-api-using-perspective-sessionid-to-authenticate/49053/4 "2021-07-21T22:44:07Z")

</div>

Got it working - thanks for your help @Kevin.Herron!
