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

JWT expiration and issuedAt properties and setters are inconsistent #93

Open
ande8135 opened this issue Nov 23, 2022 · 1 comment · May be fixed by #102
Open

JWT expiration and issuedAt properties and setters are inconsistent #93

ande8135 opened this issue Nov 23, 2022 · 1 comment · May be fixed by #102

Comments

@ande8135
Copy link

The Jwt.prototype.setIssuedAt() and .setExpiration() functions are both time-related, but take in three separate arguments of inconsistent types. IssuedAt only takes in an integer representing seconds, while Expiration can take an integer representing milliseconds, or a Date object. Can you make these arguments consistent?

njwt.create(...)
  .setIssuedAt(seconds)
  .setExpiration(date or milliseconds);

IssuedAt:

njwt/index.js

Lines 182 to 185 in ce98cd4

Jwt.prototype.setIssuedAt = function setIssuedAt(iat) {
this.body.iat = iat;
return this;
};

njwt/index.js

Lines 155 to 157 in ce98cd4

if (!this.body.iat) {
this.setIssuedAt(nowEpochSeconds());
}

njwt/index.js

Lines 38 to 40 in ce98cd4

function nowEpochSeconds(){
return Math.floor(new Date().getTime()/1000);
}

Expiration:

njwt/index.js

Line 188 in ce98cd4

this.body.exp = Math.floor((exp instanceof Date ? exp : new Date(exp)).getTime() / 1000);

@shuowu-okta
Copy link

@ande8135 Thanks for reporting the issue!

Internal Ref: OKTA-573091

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants