Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 307 redirect when refreshing tokens in background to keep HTTP method #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class Authenticator {
* @param {String} location Path to redirection.
* @return Lambda@Edge response.
*/
async _getRedirectResponse(tokens: Tokens, domain: string, location: string): Promise<CloudFrontResultResponse> {
async _getRedirectResponse(tokens: Tokens, domain: string, location: string, keepMethod: boolean = false): Promise<CloudFrontResultResponse> {
const decoded = await this._jwtVerifier.verify(tokens.idToken as string);
const username = decoded['cognito:username'] as string;
const usernameBase = `${this._cookieBase}.${username}`;
Expand Down Expand Up @@ -309,7 +309,7 @@ export class Authenticator {
}

const response: CloudFrontResultResponse = {
status: '302' ,
status: keepMethod ? '307' : '302' ,
headers: {
'location': [{
key: 'Location',
Expand Down Expand Up @@ -624,7 +624,7 @@ export class Authenticator {
if (tokens.refreshToken) {
this._logger.debug({ msg: 'Verifying idToken failed, verifying refresh token instead...', tokens, err });
return await this._fetchTokensFromRefreshToken(redirectURI, tokens.refreshToken)
.then(tokens => this._getRedirectResponse(tokens, cfDomain, request.uri));
.then(tokens => this._getRedirectResponse(tokens, cfDomain, request.uri, true));
} else {
throw err;
}
Expand Down