-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from kinde-oss/feature/extra-jwt-checks
Extra JWT checks
- Loading branch information
Showing
13 changed files
with
422 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ const idTokenStub = { | |
auth_time: 1683693508, | ||
azp: '123456789', | ||
email: '[email protected]', | ||
exp: 1683697108, | ||
exp: 1772323199, | ||
family_name: 'Lannister', | ||
given_name: 'Jaime', | ||
iat: 1683693508, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {initializeStore} from '../../testData/initializeStore'; | ||
import {accessTokenStub} from '../../testData/accessTokenStub'; | ||
import type {JWT} from './isJWTActive.types'; | ||
import {isJWTActive} from './isJWTActive'; | ||
import {store} from '../../state/store'; | ||
|
||
describe('isJWTActive util', () => { | ||
beforeEach(() => initializeStore()); | ||
|
||
test('returns false if provided token is expired', () => { | ||
const expiredToken = {...accessTokenStub, exp: 949363200}; | ||
expect(isJWTActive(expiredToken)).toBe(false); | ||
}); | ||
|
||
test('return true if provided token is not expired', () => { | ||
const unexpiredToken = store.getItem('kinde_access_token') as JWT; | ||
expect(isJWTActive(unexpiredToken)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {JWT} from './isJWTActive.types'; | ||
|
||
const LEEWAY = 60; | ||
|
||
export const isJWTActive = (jwtToken: JWT): boolean => { | ||
const unixTime = Math.floor(Date.now() / 1000); | ||
return jwtToken.exp + LEEWAY > unixTime; | ||
}; |
File renamed without changes.
Oops, something went wrong.