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

AUT-3613: Log a reauth user out if they are blocked for reauth #2014

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions src/components/authorize/authorize-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ export function authorizeGet(
setSessionDataFromClaims(req, claims);
setSessionDataFromAuthResponse(req, startAuthResponse);

if (
supportReauthentication() &&
req.session.user.reauthenticate &&
startAuthResponse.data.user.isBlockedForReauth
) {
logger.info(
`Start response indicates user with session ${res.locals.sessionId} is blocked for reauth, redirecting back to orchestration`
);
return res.redirect(
req.session.client.redirectUri.concat("?error=login_required")
);
}

req.session.user.isAccountCreationJourney = undefined;

logger.info(`Reauth claim length ${claims.reauthenticate?.length}`);
Expand Down
27 changes: 27 additions & 0 deletions src/components/authorize/tests/authorize-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ describe("authorize controller", () => {
identityRequired: false,
upliftRequired: false,
authenticated: false,
isBlockedForReauth: false,
};
fakeAuthorizeService = mockAuthService(authServiceResponseData);

Expand All @@ -239,6 +240,32 @@ describe("authorize controller", () => {
expect(res.redirect).to.have.calledWith(PATH_NAMES.ENTER_EMAIL_SIGN_IN);
});

it("should log user out when reauthentication is requested and support reauthenticate feature flag is on but user is blocked from reauthenticating", async () => {
const redirectUri = "https://example.com/redirect";
mockClaims.redirect_uri = redirectUri;

process.env.SUPPORT_REAUTHENTICATION = "1";
mockClaims.reauthenticate = "123456";
authServiceResponseData.data.user = {
identityRequired: false,
upliftRequired: false,
authenticated: false,
isBlockedForReauth: true,
};
fakeAuthorizeService = mockAuthService(authServiceResponseData);

await authorizeGet(
fakeAuthorizeService,
fakeCookieConsentService,
fakeKmsDecryptionService,
fakeJwtService
)(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(
redirectUri + "?error=login_required"
);
});

//note that this is currently the same behaviour with the feature flag on or off. This will change if we decide on a different initial page for the reauth journey
it("should redirect to sign in when reauthentication is requested and user has an existing session but support reauthenticate feature flag is off", async () => {
process.env.SUPPORT_REAUTHENTICATION = "0";
Expand Down
1 change: 1 addition & 0 deletions src/components/authorize/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface UserSessionInfo {
gaCrossDomainTrackingId?: string;
docCheckingAppUser: boolean;
mfaMethodType?: string;
isBlockedForReauth: boolean;
}

export interface AuthorizeServiceInterface {
Expand Down
Loading