Skip to content

JWT expiration and issuedAt properties and setters are inconsistent #93

Open
@ande8135

Description

@ande8135

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions