Skip to content

Commit cd0d162

Browse files
committed
Use refresh token in 2FA flow
When refactoring authentication to use refresh tokens we missed the 2FA flow. It's not clear that we should be supporting 2FA to begin with since rclone doesn't support it, and ultimately the real solution is to use keys instead of passwords for sftp authentication. That being said, while it's here we should make sure it isn't broken! Issue #298 2FA auth flow does not utilize refresh tokens
1 parent 9a83861 commit cd0d162

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/classes/AuthenticationSession.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,29 @@ export class AuthenticationSession {
205205
}).then((clientResponse) => {
206206
switch (clientResponse.statusCode) {
207207
case FusionAuthStatusCode.Success:
208-
case FusionAuthStatusCode.SuccessButUnregisteredInApp:
209-
if (clientResponse.response.token !== undefined) {
210-
logger.verbose('Successful 2FA authentication attempt.', {
211-
username: this.authContext.username,
212-
});
213-
this.authToken = clientResponse.response.token;
208+
logger.verbose('Successful 2FA authentication attempt.', {
209+
username: this.authContext.username,
210+
});
211+
if (clientResponse.response.refreshToken) {
212+
this.successHandler(clientResponse.response.refreshToken);
214213
this.authContext.accept();
215-
return;
214+
} else {
215+
logger.warn('No refresh token in response :', clientResponse.response);
216+
this.authContext.reject();
216217
}
217-
this.authContext.reject();
218218
return;
219+
case FusionAuthStatusCode.SuccessButUnregisteredInApp: {
220+
const userId = clientResponse.response.user?.id ?? '';
221+
this.registerUserInApp(userId)
222+
.then(() => {
223+
this.processTwoFactorCodeResponse([twoFactorCode]);
224+
})
225+
.catch((error) => {
226+
logger.warn('Error during registration and authentication:', error);
227+
this.authContext.reject();
228+
});
229+
return;
230+
}
219231
default:
220232
logger.verbose('Failed 2FA authentication attempt.', {
221233
username: this.authContext.username,

0 commit comments

Comments
 (0)