Building a React app using the implicit grant flow for Genesys Cloud auth. The @genesyscloud/purecloud-platform-auth library handles the token exchange, but my custom JWT validation middleware keeps rejecting the access token immediately after refresh.
The exp claim in the decoded token is always in the past, even though the token was just issued. Here’s the validation logic I’m using:
const jwt = require('jsonwebtoken');
const validateToken = (token) => {
try {
const decoded = jwt.decode(token, { complete: true });
if (!decoded) throw new Error('Invalid token');
const now = Math.floor(Date.now() / 1000);
console.log('Token exp:', decoded.payload.exp);
console.log('Current time:', now);
if (decoded.payload.exp < now) {
throw new Error('Token expired');
}
return decoded.payload;
} catch (err) {
console.error('JWT Validation Error:', err.message);
return null;
}
};
The console output shows Token exp is exactly 1 second less than Current time. Is there a clock skew issue with Genesys Cloud’s token signing, or am I missing a step in the implicit grant flow?