Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Fix jwt not active error by adding a small clock tolerence #227

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
### Fixed

- Don't include extra params when calculating local hmac [#196](https://github.com/Shopify/shopify-node-api/pull/196)
- Add a 5 second `clockTolerance` to fix `jwt not active` error [#227](https://github.com/Shopify/shopify-node-api/pull/227)
- [Breaking] Change default for OAuth.beginAuth to online sessions [#203](https://github.com/Shopify/shopify-node-api/pull/203)
- [Breaking] Return and delete session in `validateAuthCallback` [#217](https://github.com/Shopify/shopify-node-api/pull/217)
- [Breaking] Extract `addHandler` and `getHandler` methods for webhooks out of `register` [#205](https://github.com/Shopify/shopify-node-api/pull/205)
Expand Down
3 changes: 3 additions & 0 deletions src/utils/decode-session-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as ShopifyErrors from '../error';

import validateShop from './shop-validator';

const JWT_PERMITTED_CLOCK_TOLERANCE = 5;

interface JwtPayload {
iss: string;
dest: string;
Expand All @@ -27,6 +29,7 @@ function decodeSessionToken(token: string): JwtPayload {
try {
payload = jwt.verify(token, Context.API_SECRET_KEY, {
algorithms: ['HS256'],
clockTolerance: JWT_PERMITTED_CLOCK_TOLERANCE,
}) as JwtPayload;
} catch (error) {
throw new ShopifyErrors.InvalidJwtError(
Expand Down