Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/added is jwt expiration #2299

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.acceptSuggestionOnEnter": "on"
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import isBIC from './lib/isBIC';
import isMD5 from './lib/isMD5';
import isHash from './lib/isHash';
import isJWT from './lib/isJWT';
import isJWTExpiration from './lib/isJWTExpiration';

import isJSON from './lib/isJSON';
import isEmpty from './lib/isEmpty';
Expand Down Expand Up @@ -177,6 +178,7 @@ const validator = {
isMD5,
isHash,
isJWT,
isJWTExpiration,
isJSON,
isEmpty,
isLength,
Expand Down
19 changes: 19 additions & 0 deletions src/lib/isJWTExpiration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default function isJWTExpiration(token) {
if (!token || typeof token !== 'string') {

Check failure on line 2 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Expected indentation of 2 spaces but found 4

Check failure on line 2 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Expected indentation of 2 spaces but found 4

Check failure on line 2 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Expected indentation of 2 spaces but found 4

Check failure on line 2 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Expected indentation of 2 spaces but found 4
return false;

Check failure on line 3 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Expected indentation of 4 spaces but found 8

Check failure on line 3 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Expected indentation of 4 spaces but found 8

Check failure on line 3 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Expected indentation of 4 spaces but found 8

Check failure on line 3 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Expected indentation of 4 spaces but found 8
}

Check failure on line 4 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Expected indentation of 2 spaces but found 4

Check failure on line 4 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Expected indentation of 2 spaces but found 4

Check failure on line 4 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Expected indentation of 2 spaces but found 4

Check failure on line 4 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Expected indentation of 2 spaces but found 4
try {

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Expected indentation of 2 spaces but found 4

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Block must not be padded by blank lines

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Expected indentation of 2 spaces but found 4

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Block must not be padded by blank lines

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Expected indentation of 2 spaces but found 4

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Block must not be padded by blank lines

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Expected indentation of 2 spaces but found 4

Check failure on line 5 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Block must not be padded by blank lines

Check failure on line 6 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Trailing spaces not allowed

Check failure on line 6 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Trailing spaces not allowed

Check failure on line 6 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Trailing spaces not allowed

Check failure on line 6 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Trailing spaces not allowed
const payload = JSON.parse(atob(token.split('.')[1]));

Check failure on line 7 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Expected indentation of 4 spaces but found 6

Check failure on line 7 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Expected indentation of 4 spaces but found 6

Check failure on line 7 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Expected indentation of 4 spaces but found 6

Check failure on line 7 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Expected indentation of 4 spaces but found 6

Check failure on line 8 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Trailing spaces not allowed

Check failure on line 8 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Trailing spaces not allowed

Check failure on line 8 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Trailing spaces not allowed

Check failure on line 8 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Trailing spaces not allowed
if (payload.exp && typeof payload.exp === 'number') {

Check failure on line 9 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Expected indentation of 4 spaces but found 6

Check failure on line 9 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Expected indentation of 4 spaces but found 6

Check failure on line 9 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Expected indentation of 4 spaces but found 6

Check failure on line 9 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Expected indentation of 4 spaces but found 6
const currentTimestamp = Math.floor(Date.now() / 1000);

Check failure on line 10 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 14

Expected indentation of 6 spaces but found 8

Check failure on line 10 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 12

Expected indentation of 6 spaces but found 8

Check failure on line 10 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 10

Expected indentation of 6 spaces but found 8

Check failure on line 10 in src/lib/isJWTExpiration.js

View workflow job for this annotation

GitHub Actions / Run tests on Node.js 8

Expected indentation of 6 spaces but found 8
return payload.exp >= currentTimestamp;
}

return false;
} catch (error) {
return false;
}
}

Loading