Skip to content

Commit

Permalink
feat: add RPError indicators for unix timestamp comparison failures
Browse files Browse the repository at this point in the history
closes #250
  • Loading branch information
panva committed Apr 28, 2020
1 parent 69214ec commit fe3db5c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
if (maxAge && (payload.auth_time + maxAge < timestamp - this[CLOCK_TOLERANCE])) {
throw new RPError({
printf: ['too much time has elapsed since the last End-User authentication, max_age %i, auth_time: %i, now %i', maxAge, payload.auth_time, timestamp - this[CLOCK_TOLERANCE]],
now: timestamp,
tolerance: this[CLOCK_TOLERANCE],
auth_time: payload.auth_time,
jwt: idToken,
});
}
Expand Down Expand Up @@ -754,6 +757,9 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
if (payload.iat < timestamp - 3600) {
throw new RPError({
printf: ['JWT issued too far in the past, now %i, iat %i', timestamp, payload.iat],
now: timestamp,
tolerance: this[CLOCK_TOLERANCE],
iat: payload.iat,
jwt: idToken,
});
}
Expand Down Expand Up @@ -864,6 +870,9 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
if (payload.nbf > timestamp + this[CLOCK_TOLERANCE]) {
throw new RPError({
printf: ['JWT not active yet, now %i, nbf %i', timestamp + this[CLOCK_TOLERANCE], payload.nbf],
now: timestamp,
tolerance: this[CLOCK_TOLERANCE],
nbf: payload.nbf,
jwt,
});
}
Expand All @@ -879,6 +888,9 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
if (timestamp - this[CLOCK_TOLERANCE] >= payload.exp) {
throw new RPError({
printf: ['JWT expired, now %i, exp %i', timestamp - this[CLOCK_TOLERANCE], payload.exp],
now: timestamp,
tolerance: this[CLOCK_TOLERANCE],
exp: payload.exp,
jwt,
});
}
Expand Down
6 changes: 6 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,5 +779,11 @@ export namespace errors {
* from got.
*/
response?: any;
now?: number;
tolerance?: number;
nbf?: number;
exp?: number;
iat?: number;
auth_time?: number;
}
}

0 comments on commit fe3db5c

Please sign in to comment.