# Access Token validation in middle-ware

**URL:** <https://discourse.nodered.org/t/access-token-validation-in-middle-ware/90044>\
**Category:** General\
**Tags:** security\
**Created:** [7 August 2024 21:43 UTC](https://discourse.nodered.org/t/access-token-validation-in-middle-ware/90044 "2024-08-07T21:43:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriharsha-bhasuru](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sriharsha-bhasuru/32/93441_2.png) [@sriharsha-bhasuru](https://discourse.nodered.org/u/sriharsha-bhasuru)\
**Post date:** [7 August 2024 21:43 UTC](https://discourse.nodered.org/t/access-token-validation-in-middle-ware/90044/1 "2024-08-07T21:43:59Z")

</div>

New & learning Node-Red, need help in understanding access\_tokens

Enabled adminAuth module and was able to get tokens from token endpoint. Created a flow that takes HTTP-IN of type GET with url **/test** and returns hello-world as response.

API is accessible on 127.0.0.1:1880/test, I want to add authorization for this endpoint. Is there a way in middle-ware I can access the storage as below or any better way of handling this.

```auto
    async function isTokenValid(token) {
    try {
        if (!NodeRED.settings.storage) {
            await NodeRED.init();
        }

        const storage = NodeRED.settings.storage;
        const sessions = await storage.getSessions();

        const session = sessions[token];

        if (session && session.expires > Date.now()) {
            return true;
        }

        return false;
    } catch (error) {
        console.error('Error checking token validity:', error);
        return false;
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 November 2024 21:44 UTC](https://discourse.nodered.org/t/access-token-validation-in-middle-ware/90044/2 "2024-11-05T21:44:50Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
