World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#11686] web-v2(UI): remove simpleAuthUser for oauth mode and config request headers by authType (#11703)
Qian Xiae20c645bab32
diff --git a/web-v2/web/src/lib/provider/IdleSessionProvider.js b/web-v2/web/src/lib/provider/IdleSessionProvider.jsindex 1ac2e05829..4b3422bc84 100644--- a/web-v2/web/src/lib/provider/IdleSessionProvider.js+++ b/web-v2/web/src/lib/provider/IdleSessionProvider.js@@ -83,8 +83,13 @@ export default function IdleSessionProvider({const authType = useAppSelector(state => state.auth.authType)const authToken = useAppSelector(state => state.auth.authToken)- // Only enable idle timeout when the user is authenticated and not on login page- const isAuthenticated = authType === 'simple' ? !!sessionStorage.getItem('simpleAuthUser') : !!authToken+ // Only enable idle timeout when the user is authenticated and not on login page.+ // During bootstrap (authType === null), fall back to persisted token in localStorage+ // to avoid prematurely treating the user as unauthenticated.+ const isAuthenticated =+ authType === 'simple'+ ? !!sessionStorage.getItem('simpleAuthUser')+ : !!(authToken || (authType === null && localStorage.getItem('accessToken')))const isLoginPage = pathname === '/login'const [state, setState] = useState('active')diff --git a/web-v2/web/src/lib/provider/session.js b/web-v2/web/src/lib/provider/session.jsindex 5112259008..deab2c948c 100644--- a/web-v2/web/src/lib/provider/session.js+++ b/web-v2/web/src/lib/provider/session.js@@ -101,6 +101,10 @@ const AuthProvider = ({ children }) => {goToMetalakeListPage()}} else if (authType === 'oauth') {+ // Clear any residual simpleAuthUser when authType is oauth+ sessionStorage.removeItem('simpleAuthUser')+ sessionStorage.removeItem('simpleAuthToken')+const tokenToUse = await oauthProviderFactory.getAccessToken()const user = await oauthProviderFactory.getUserProfile()diff --git a/web-v2/web/src/lib/store/auth/index.js b/web-v2/web/src/lib/store/auth/index.jsindex bfa8bac819..a7aa56ed72 100644--- a/web-v2/web/src/lib/store/auth/index.js+++ b/web-v2/web/src/lib/store/auth/index.js@@ -49,6 +49,9 @@ export const getAuthConfigs = createAsyncThunk('auth/getAuthConfigs', async () =localStorage.setItem('oauthUrl', oauthUrl)+ // Persist authType for axios interceptor to avoid circular dependency with Redux store+ localStorage.setItem('authType', authType)+return { oauthUrl, authType, anthEnable, serviceAdmins, systemConfig: res }})@@ -150,11 +153,16 @@ export const logoutAction = createAsyncThunk(dispatch(clearIntervalId())dispatch(setAuthToken(''))- dispatch(setAuthUser(null))- } else {- dispatch(setAuthUser(null))}+ // Always clear authUser in Redux and sessionStorage on logout+ // This ensures consistent behavior for both OAuth and simple auth+ dispatch(setAuthUser(null))+ sessionStorage.removeItem('simpleAuthToken')++ // Clear persisted authType to avoid stale auth mode on next visit+ localStorage.removeItem('authType')+// Reset provider factory to ensure clean state for next loginoauthProviderFactory.reset()diff --git a/web-v2/web/src/lib/utils/axios/index.js b/web-v2/web/src/lib/utils/axios/index.jsindex d9df97f88d..00e8c0fd02 100644--- a/web-v2/web/src/lib/utils/axios/index.js+++ b/web-v2/web/src/lib/utils/axios/index.js@@ -180,19 +180,36 @@ const transform = {return config}- // Use OAuth provider factory for proper token management+ // Get authType from localStorage (persisted by getAuthConfigs)+ // to avoid circular dependency with Redux store+ const authType = localStorage.getItem('authType')+try {- const token = await oauthProviderFactory.getAccessToken()-- if (token && config?.requestOptions?.withToken !== false) {- // ** jwt token- config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` : token- } else if (window.sessionStorage.getItem('simpleAuthUser')) {- // Simple auth fallback- const simpleAuthToken = window.sessionStorage.getItem('simpleAuthToken')+ if (authType === 'oauth') {+ // OAuth auth: use Bearer token from OAuth provider+ const token = await oauthProviderFactory.getAccessToken()++ if (token && config?.requestOptions?.withToken !== false) {+ // ** jwt token+ config.headers.Authorization = options.authenticationScheme+ ? `${options.authenticationScheme} ${token}`+ : token+ }+ } else if (authType === 'simple') {+ // Simple auth: use Basic auth with username from sessionStorageconst user = JSON.parse(window.sessionStorage.getItem('simpleAuthUser'))?.nameif (user) {- config.headers.Authorization = `Basic ${Buffer.from(user || '').toString('base64')}`+ config.headers.Authorization = `Basic ${Buffer.from(user).toString('base64')}`+ }+ } else {+ // authType not yet persisted during bootstrap (before /configs resolves).+ // Fall back to persisted auth artifacts to avoid spurious 401s.+ // localStorage.accessToken indicates a prior OAuth session (simple auth doesn't persist tokens).+ const persistedToken = localStorage.getItem('accessToken')+ if (persistedToken && config?.requestOptions?.withToken !== false) {+ config.headers.Authorization = options.authenticationScheme+ ? `${options.authenticationScheme} ${persistedToken}`+ : persistedToken}}} catch (error) {@@ -250,9 +267,14 @@ const transform = {checkStatus(error?.response?.status, msg, errorMessageMode)if (response?.status === 401 && !originConfig._retry && response.config.url !== githubApis.GET) {+ // Clear OAuth tokenslocalStorage.removeItem('accessToken')localStorage.removeItem('authParams')+ // Clear simple auth data+ sessionStorage.removeItem('simpleAuthUser')+ sessionStorage.removeItem('simpleAuthToken')+try {const provider = await oauthProviderFactory.getProvider()if (provider && provider.clearAuthData) {