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.
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;
}
}