Context
- node version: 18.20.4
- module version with issue: 5.0.0
- last module version without issue:
- environment (e.g. node, browser, native): node
- any other relevant information:
What are you trying to achieve or the steps to reproduce?
I have authorization_code grant type and trying to create an AccessToken instance from what I have stored in database. The access token stored in the database has the following properties:
const tokenFromDB = {
access_token: 'MY ACCES TOKEN',
refresh_token: 'MY REFRESH TOKEN',
expires_in: 43200,
scope: 'offline_access eq1',
token_type: 'Bearer',
created_at: 1729699637, // October 23, 2024 4:07:17 PM
};
When I execute the createToken method I got always a token that said is not expired, despite it is.
What was the result you got?
The result I got is the following:
const accessToken = client.createToken(tokenFromDB);
console.log(accessToken);
// AccessToken {
// token: {
// access_token: 'MY ACCESS TOKEN',
// refresh_token: 'MY REFRESH TOKEN',
// expires_in: 43200,
// scope: 'offline_access eq1',
// token_type: 'Bearer',
// created_at: 1729699637,
// expires_at: 2024-10-26T10:48:59.998Z // <=== THIS SHOULD BE 2024-10-24T04:07:17.000Z
// }
// }
What result did you expect?
const accessToken = client.createToken(tokenFromDB);
console.log(accessToken);
// AccessToken {
// token: {
// access_token: 'MY ACCESS TOKEN',
// refresh_token: 'MY REFRESH TOKEN',
// expires_in: 43200,
// scope: 'offline_access eq1',
// token_type: 'Bearer',
// created_at: 1729699637,
// expires_at: 2024-10-24T04:07:17.000Z
// }
// }
I think the problem is here:
|
function getExpirationDate(expiresIn) { |
|
return new Date(Date.now() + Number.parseInt(expiresIn, 10) * 1000); |
|
} |
This function should accept also the parameter created_at. It always get the expiration date relative to now. I think the function should be something like that:
function getExpirationDate(expiresIn, createdAt) {
return new Date( (createdAt || Date.now()) + Number.parseInt(expiresIn, 10) * 1000);
}
Context
What are you trying to achieve or the steps to reproduce?
I have authorization_code grant type and trying to create an AccessToken instance from what I have stored in database. The access token stored in the database has the following properties:
When I execute the createToken method I got always a token that said is not expired, despite it is.
What was the result you got?
The result I got is the following:
What result did you expect?
I think the problem is here:
simple-oauth2/lib/access-token-parser.js
Lines 8 to 10 in bee1539
This function should accept also the parameter
created_at. It always get the expiration date relative to now. I think the function should be something like that: