feat: Add OIDC debug mode

This commit is contained in:
Maksim Eltyshev
2026-01-27 22:34:08 +01:00
parent 2c4369159b
commit d688a64e36
52 changed files with 349 additions and 24 deletions
+7
View File
@@ -54,6 +54,13 @@ authenticateWithOidc.failure = (error, terms) => ({
},
});
authenticateWithOidc.debug = (logs) => ({
type: ActionTypes.WITH_OIDC_AUTHENTICATE__DEBUG,
payload: {
logs,
},
});
const clearAuthenticateError = () => ({
type: ActionTypes.AUTHENTICATE_ERROR_CLEAR,
payload: {},
+3
View File
@@ -13,6 +13,8 @@ const createAccessToken = (data, headers) =>
const exchangeForAccessTokenWithOidc = (data, headers) =>
http.post('/access-tokens/exchange-with-oidc?withHttpOnlyToken=true', data, headers);
const debugOidc = (data, headers) => http.post('/access-tokens/debug-oidc', data, headers);
// TODO: rename?
const acceptTerms = (data, headers) => http.post('/access-tokens/accept-terms', data, headers);
@@ -24,6 +26,7 @@ const deleteCurrentAccessToken = (headers) => http.delete('/access-tokens/me', u
export default {
createAccessToken,
exchangeForAccessTokenWithOidc,
debugOidc,
acceptTerms,
revokePendingToken,
deleteCurrentAccessToken,
+32 -18
View File
@@ -8,7 +8,8 @@ import React, { useCallback, useEffect, useMemo } from 'react';
import classNames from 'classnames';
import { useDispatch, useSelector } from 'react-redux';
import { useTranslation, Trans } from 'react-i18next';
import { Button, Divider, Form, Grid, Header, Message } from 'semantic-ui-react';
import TextareaAutosize from 'react-textarea-autosize';
import { Button, Divider, Form, Grid, Header, Message, TextArea } from 'semantic-ui-react';
import { useDidUpdate, usePrevious, useToggle } from '../../../lib/hooks';
import { Input } from '../../../lib/custom-ui';
@@ -23,7 +24,7 @@ import logo from '../../../assets/images/logo.png';
import styles from './Content.module.scss';
const createMessage = (error) => {
const createMessage = (error, isDebug) => {
if (!error) {
return error;
}
@@ -82,7 +83,7 @@ const createMessage = (error) => {
default:
return {
type: 'warning',
content: 'common.unknownError',
content: isDebug ? error.message : 'common.unknownError',
};
}
};
@@ -95,6 +96,7 @@ const Content = React.memo(() => {
isSubmitting,
isSubmittingWithOidc,
error,
debugLogs,
step,
} = useSelector(selectors.selectAuthenticateForm);
@@ -124,7 +126,11 @@ const Content = React.memo(() => {
return initialData;
});
const message = useMemo(() => createMessage(error), [error]);
const withOidc = !!bootstrap.oidc;
const isOidcEnforced = withOidc && bootstrap.oidc.isEnforced;
const isOidcDebug = withOidc && bootstrap.oidc.debug;
const message = useMemo(() => createMessage(error, isOidcDebug), [error, isOidcDebug]);
const [focusPasswordFieldState, focusPasswordField] = useToggle();
const [emailOrUsernameFieldRef, handleEmailOrUsernameFieldRef] = useNestedRef('inputRef');
@@ -157,14 +163,11 @@ const Content = React.memo(() => {
dispatch(entryActions.clearAuthenticateError());
}, [dispatch]);
const withOidc = !!bootstrap.oidc;
const isOidcEnforced = withOidc && bootstrap.oidc.isEnforced;
useEffect(() => {
if (!isOidcEnforced) {
emailOrUsernameFieldRef.current.focus();
}
}, [emailOrUsernameFieldRef, isOidcEnforced]);
}, [isOidcEnforced, emailOrUsernameFieldRef]);
useDidUpdate(() => {
if (wasSubmitting && !isSubmitting && error) {
@@ -269,16 +272,27 @@ const Content = React.memo(() => {
</>
)}
{withOidc && (
<Button
fluid
primary={isOidcEnforced}
icon={isOidcEnforced ? 'right arrow' : undefined}
labelPosition={isOidcEnforced ? 'right' : undefined}
content={t('action.logInWithSso')}
loading={isSubmittingWithOidc}
disabled={isSubmitting || isSubmittingWithOidc}
onClick={handleAuthenticateWithOidcClick}
/>
<>
<Button
fluid
primary={isOidcDebug ? undefined : isOidcEnforced}
color={isOidcDebug ? 'orange' : undefined}
icon={isOidcEnforced ? 'right arrow' : undefined}
labelPosition={isOidcEnforced ? 'right' : undefined}
content={isOidcDebug ? t('action.debugSso') : t('action.logInWithSso')}
loading={isSubmittingWithOidc}
disabled={isSubmitting || isSubmittingWithOidc}
onClick={handleAuthenticateWithOidcClick}
/>
{debugLogs && (
<TextArea
readOnly
as={TextareaAutosize}
value={debugLogs.join('\n')}
className={styles.debugLog}
/>
)}
</>
)}
</div>
<div className={styles.poweredBy}>
@@ -19,6 +19,16 @@
width: 100%;
}
.debugLog {
border: 1px solid rgba(9, 30, 66, 0.13);
border-radius: 3px;
color: #333;
line-height: 1.4;
margin-top: 16px;
padding: 8px 12px;
width: 100%;
}
.divider {
font-weight: normal;
}
+1
View File
@@ -29,6 +29,7 @@ export default {
WITH_OIDC_AUTHENTICATE: 'WITH_OIDC_AUTHENTICATE',
WITH_OIDC_AUTHENTICATE__SUCCESS: 'WITH_OIDC_AUTHENTICATE__SUCCESS',
WITH_OIDC_AUTHENTICATE__FAILURE: 'WITH_OIDC_AUTHENTICATE__FAILURE',
WITH_OIDC_AUTHENTICATE__DEBUG: 'WITH_OIDC_AUTHENTICATE__DEBUG',
AUTHENTICATE_ERROR_CLEAR: 'AUTHENTICATE_ERROR_CLEAR',
TERMS_ACCEPT: 'TERMS_ACCEPT',
TERMS_ACCEPT__SUCCESS: 'TERMS_ACCEPT__SUCCESS',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: 'إلغاء وإغلاق',
continue: 'متابعة',
debugSso: 'تصحيح أخطاء تسجيل الدخول الموحد',
goBack: 'العودة',
goHome: 'الذهاب للرئيسية',
logIn: 'تسجيل الدخول',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Отказ и затваряне',
continue: 'Продължи',
debugSso: 'Дебъгване на SSO',
goBack: 'Назад',
goHome: 'Към началото',
logIn: 'Вход',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Cancel·lar i tancar',
continue: 'Continuar',
debugSso: 'Depurar SSO',
goBack: 'Tornar',
goHome: "Anar a l'inici",
logIn: 'Iniciar sessió',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Zrušit a zavřít',
continue: 'Pokračovat',
debugSso: 'Ladit SSO',
goBack: 'Zpět',
goHome: 'Domů',
logIn: 'Přihlásit se',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Annuller og luk',
continue: 'Fortsæt',
debugSso: 'Fejlfind SSO',
goBack: 'Gå tilbage',
goHome: 'Gå hjem',
logIn: 'Log på',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Abbrechen und schließen',
continue: 'Fortfahren',
debugSso: 'SSO debuggen',
goBack: 'Zurück gehen',
goHome: 'Zur Startseite',
logIn: 'Einloggen',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Ακύρωση και κλείσιμο',
continue: 'Συνέχεια',
debugSso: 'Αποσφαλμάτωση SSO',
goBack: 'Επιστροφή',
goHome: 'Αρχική σελίδα',
logIn: 'Σύνδεση',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: 'Cancel and close',
continue: 'Continue',
debugSso: 'Debug SSO',
goBack: 'Go back',
goHome: 'Go home',
logIn: 'Log in',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: 'Cancel and close',
continue: 'Continue',
debugSso: 'Debug SSO',
goBack: 'Go back',
goHome: 'Go home',
logIn: 'Log in',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Cancelar y cerrar',
continue: 'Continuar',
debugSso: 'Depurar SSO',
goBack: 'Volver',
goHome: 'Ir al inicio',
logIn: 'Iniciar sesión',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Tühista ja sulge',
continue: 'Jätka',
debugSso: 'Siluda SSO',
goBack: 'Tagasi',
goHome: 'Koju',
logIn: 'Logi sisse',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: 'لغو و بستن',
continue: 'ادامه',
debugSso: 'اشکال‌زدایی SSO',
goBack: 'بازگشت',
goHome: 'رفتن به خانه',
logIn: 'ورود',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Peruuta ja sulje',
continue: 'Jatka',
debugSso: 'Korjaa SSO-virheitä',
goBack: 'Takaisin',
goHome: 'Kotiin',
logIn: 'Kirjaudu sisään',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Annuler et fermer',
continue: 'Continuer',
debugSso: 'Déboguer le SSO',
goBack: 'Retour',
goHome: "Aller à l'accueil",
logIn: 'Se connecter',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Mégse és bezárás',
continue: 'Folytatás',
debugSso: 'SSO hibakeresése',
goBack: 'Vissza',
goHome: 'Kezdőlapra',
logIn: 'Belépés',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Batal dan tutup',
continue: 'Lanjutkan',
debugSso: 'Debug SSO',
goBack: 'Kembali',
goHome: 'Ke beranda',
logIn: 'Masuk',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Annulla e chiudi',
continue: 'Continua',
debugSso: 'Debug SSO',
goBack: 'Torna indietro',
goHome: 'Vai alla home',
logIn: 'Accedi',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'キャンセルして閉じる',
continue: '続行',
debugSso: 'SSOをデバッグ',
goBack: '戻る',
goHome: 'ホームへ',
logIn: 'ログイン',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: '취소 후 닫기',
continue: '계속',
debugSso: 'SSO 디버그',
goBack: '뒤로 가기',
goHome: '홈으로 가기',
logIn: '로그인',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Annuleren en sluiten',
continue: 'Doorgaan',
debugSso: 'SSO debuggen',
goBack: 'Terug gaan',
goHome: 'Naar startpagina',
logIn: 'Inloggen',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Anuluj i zamknij',
continue: 'Kontynuuj',
debugSso: 'Debuguj SSO',
goBack: 'Wróć',
goHome: 'Idź do domu',
logIn: 'Zaloguj',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Cancelar e fechar',
continue: 'Continuar',
debugSso: 'Depurar SSO',
goBack: 'Voltar',
goHome: 'Ir para início',
logIn: 'Entrar',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Cancelar e fechar',
continue: 'Continuar',
debugSso: 'Depurar SSO',
goBack: 'Voltar',
goHome: 'Ir para início',
logIn: 'Iniciar sessão',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Anulează și închide',
continue: 'Continuă',
debugSso: 'Depanează SSO',
goBack: 'Înapoi',
goHome: 'Acasă',
logIn: 'Autentificarea',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Отменить и закрыть',
continue: 'Продолжить',
debugSso: 'Отладить SSO',
goBack: 'Назад',
goHome: 'На главную',
logIn: 'Войти',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Zrušiť a zavrieť',
continue: 'Pokračovať',
debugSso: 'Ladiť SSO',
goBack: 'Ísť späť',
goHome: 'Ísť domov',
logIn: 'Prihlásiť sa',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Откажи и затвори',
continue: 'Настави',
debugSso: 'Дебагуј SSO',
goBack: 'Назад',
goHome: 'Иди кући',
logIn: 'Пријава',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Otkaži i zatvori',
continue: 'Nastavi',
debugSso: 'Debaguj SSO',
goBack: 'Nazad',
goHome: 'Idi kući',
logIn: 'Prijava',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Avbryt och stäng',
continue: 'Fortsätt',
debugSso: 'Felsök SSO',
goBack: 'Gå tillbaka',
goHome: 'Gå hem',
logIn: 'Logga in',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: 'İptal et ve kapat',
continue: 'Devam et',
debugSso: 'SSO hatalarını ayıkla',
goBack: 'Geri dön',
goHome: 'Ana sayfaya git',
logIn: 'Giriş yap',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Скасувати та закрити',
continue: 'Продовжити',
debugSso: 'Відлагодити SSO',
goBack: 'Назад',
goHome: 'На головну',
logIn: 'Увійти',
+1
View File
@@ -26,6 +26,7 @@ export default {
action: {
cancelAndClose: 'Bekor qilish va yopish',
continue: 'Davom etish',
debugSso: 'SSO ni tuzatish',
goBack: 'Orqaga',
goHome: 'Bosh sahifaga',
logIn: 'Kirish',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: 'Hủy và đóng',
continue: 'Tiếp tục',
debugSso: 'Gỡ lỗi SSO',
goBack: 'Quay lại',
goHome: 'Về trang chủ',
logIn: 'Đăng nhập',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: '取消并关闭',
continue: '继续',
debugSso: '调试SSO',
goBack: '返回',
goHome: '回到首页',
logIn: '登录',
+1
View File
@@ -25,6 +25,7 @@ export default {
action: {
cancelAndClose: '取消並關閉',
continue: '繼續',
debugSso: '偵錯SSO',
goBack: '返回',
goHome: '回到首頁',
logIn: '登入',
@@ -16,6 +16,7 @@ const initialState = {
isSubmitting: false,
isSubmittingWithOidc: false,
error: null,
debugLogs: null,
pendingToken: null,
step: null,
termsForm: {
@@ -91,6 +92,12 @@ export default (state = initialState, { type, payload }) => {
isSubmittingWithOidc: false,
error: payload.error,
};
case ActionTypes.WITH_OIDC_AUTHENTICATE__DEBUG:
return {
...state,
isSubmittingWithOidc: false,
debugLogs: payload.logs,
};
case ActionTypes.AUTHENTICATE_ERROR_CLEAR:
return {
...state,
+14
View File
@@ -106,6 +106,20 @@ export function* authenticateWithOidcCallback() {
return;
}
const oidcBootstrap = yield select(selectors.selectOidcBootstrap);
if (oidcBootstrap?.debug) {
const {
included: { logs },
} = yield call(api.debugOidc, {
code,
nonce,
});
yield put(actions.authenticateWithOidc.debug(logs));
return;
}
let accessToken;
try {
({ item: accessToken } = yield call(api.exchangeForAccessTokenWithOidc, {