Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/targets/initiateAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
InitiateAuthRequest,
InitiateAuthResponse,
} from "aws-sdk/clients/cognitoidentityserviceprovider";
import jwt, { JwtPayload } from "jsonwebtoken";
import { v4 } from "uuid";
import {
InvalidParameterError,
Expand Down Expand Up @@ -233,6 +234,17 @@ const refreshTokenAuthFlow = async (
throw new InvalidParameterError("AuthParameters REFRESH_TOKEN is required");
}

// check if the refresh token is expired
const decodedRefreshToken = jwt.decode(
req.AuthParameters.REFRESH_TOKEN
) as JwtPayload;
if (
!decodedRefreshToken.exp ||
(decodedRefreshToken.exp && decodedRefreshToken.exp < Date.now() / 1000)
) {
throw new NotAuthorizedError();
}

const user = await userPool.getUserByRefreshToken(
ctx,
req.AuthParameters.REFRESH_TOKEN
Expand Down
Loading