Skip to content

Commit 0498ae1

Browse files
committed
🚧(auth) implement first draft of silent login with prompt=None
Add initial naive implementation of silent login functionality using prompt=None parameter to request OIDC provider to skip login screen and return proper HTTP error response instead. Known issue: Homepage flickering occurs when silent login is triggered. Further investigation and fixes needed to resolve UI state management during silent authentication attempts.
1 parent 315158d commit 0498ae1

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/backend/impress/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ class Base(Configuration):
467467
)
468468

469469
# OIDC - Authorization Code Flow
470+
OIDC_AUTHENTICATE_CLASS = "lasuite.oidc_login.views.OIDCAuthenticationRequestView"
471+
OIDC_CALLBACK_CLASS = "lasuite.oidc_login.views.OIDCAuthenticationCallbackView"
470472
OIDC_CREATE_USER = values.BooleanValue(
471473
default=True,
472474
environ_name="OIDC_CREATE_USER",

src/frontend/apps/impress/src/features/auth/api/useAuthQuery.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { APIError, errorCauses, fetchAPI } from '@/api';
44
import { DEFAULT_QUERY_RETRY } from '@/core';
55

66
import { User } from './types';
7+
import {attemptSilentLogin, canAttemptSilentLogin} from "@/features/auth/silentLogin";
78

89
/**
910
* Asynchronously retrieves the current user's data from the API.
@@ -18,6 +19,10 @@ import { User } from './types';
1819
export const getMe = async (): Promise<User> => {
1920
const response = await fetchAPI(`users/me/`);
2021

22+
if (!response.ok && response.status == 401 && canAttemptSilentLogin()) {
23+
attemptSilentLogin(30);
24+
}
25+
2126
if (!response.ok) {
2227
throw new APIError(
2328
`Couldn't fetch user data: ${response.statusText}`,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { gotoLogin } from '@/features/auth'
2+
3+
const SILENT_LOGIN_RETRY_KEY = 'silent-login-retry';
4+
5+
const isRetryAllowed = () => {
6+
const lastRetryDate = localStorage.getItem(SILENT_LOGIN_RETRY_KEY);
7+
if (!lastRetryDate) {
8+
return true;
9+
}
10+
const now = new Date();
11+
return now.getTime() > Number(lastRetryDate);
12+
};
13+
14+
const setNextRetryTime = (retryIntervalInSeconds: number) => {
15+
const now = new Date();
16+
const nextRetryTime = now.getTime() + retryIntervalInSeconds * 1000;
17+
localStorage.setItem(SILENT_LOGIN_RETRY_KEY, String(nextRetryTime));
18+
};
19+
20+
const initiateSilentLogin = () => {
21+
const currentPath = window.location.pathname;
22+
gotoLogin(currentPath, true);
23+
};
24+
25+
export const canAttemptSilentLogin = () => {
26+
return isRetryAllowed();
27+
};
28+
29+
export const attemptSilentLogin = (retryIntervalInSeconds: number) => {
30+
if (!isRetryAllowed()) {
31+
return;
32+
}
33+
setNextRetryTime(retryIntervalInSeconds);
34+
initiateSilentLogin();
35+
};

src/frontend/apps/impress/src/features/auth/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { terminateCrispSession } from '@/services/Crisp';
33

44
import { LOGIN_URL, LOGOUT_URL } from './conf';
55

6-
export const gotoLogin = (returnTo = '/') => {
7-
const authenticateUrl = LOGIN_URL + `?returnTo=${backendUrl() + returnTo}`;
6+
export const gotoLogin = (returnTo = '/', isSilent = false) => {
7+
const authenticateUrl = LOGIN_URL + `?silent=${encodeURIComponent(isSilent)}&returnTo=${backendUrl() + returnTo}`;
88
window.location.replace(authenticateUrl);
99
};
1010

0 commit comments

Comments
 (0)