From 51addd4a31e63bdaab64b422f35432571af7da23 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Sat, 5 Dec 2020 13:12:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20RefreshAuth=20-=20refresh=20toke?= =?UTF-8?q?ns=20now=20working=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #12 --- src/models/creation/RefreshAuth.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/models/creation/RefreshAuth.ts b/src/models/creation/RefreshAuth.ts index 96721ab..ab947e6 100644 --- a/src/models/creation/RefreshAuth.ts +++ b/src/models/creation/RefreshAuth.ts @@ -20,7 +20,6 @@ export class RefreshAuth { } catch (error) { throw new IllegalJWTError() } - console.log(decoded["userid"]); const found_user = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"] }); if (!found_user) { throw new UserNotFoundError() @@ -28,12 +27,22 @@ export class RefreshAuth { if (found_user.refreshTokenCount !== decoded["refreshtokencount"]) { throw new RefreshTokenCountInvalidError() } - console.log(found_user); - // delete found_user.password; - newAuth.access_token = "ja" - newAuth.access_token_expires_at = 5555555 - newAuth.refresh_token = "ja" - newAuth.refresh_token_expires_at = 555555 + delete found_user.password; + const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60 + delete found_user.password; + newAuth.access_token = jsonwebtoken.sign({ + userdetails: found_user, + exp: timestamp_accesstoken_expiry + }, "securekey") + newAuth.access_token_expires_at = timestamp_accesstoken_expiry + // + const timestamp_refresh_expiry = Math.floor(Date.now() / 1000) + 10 * 36000 + newAuth.refresh_token = jsonwebtoken.sign({ + refreshtokencount: found_user.refreshTokenCount, + userid: found_user.id, + exp: timestamp_refresh_expiry + }, "securekey") + newAuth.refresh_token_expires_at = timestamp_refresh_expiry return newAuth; }