This is an automated email from the ASF dual-hosted git repository.
mchades pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.3 by this push:
new b857c928b0 [Cherry-pick to branch-1.3] [#11686] web-v2(UI): remove
simpleAuthUser for oauth mode and config request headers by authType (#11703)
(#11710)
b857c928b0 is described below
commit b857c928b03cda171145d17d6cdf883d96b29a39
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jun 17 18:16:53 2026 +0800
[Cherry-pick to branch-1.3] [#11686] web-v2(UI): remove simpleAuthUser for
oauth mode and config request headers by authType (#11703) (#11710)
**Cherry-pick Information:**
- Original commit: e20c645bab321b9b77e7fee0b2025708749916fd
- Target branch: `branch-1.3`
- Status: ✅ Clean cherry-pick (no conflicts)
Co-authored-by: Qian Xia <[email protected]>
---
web-v2/web/src/lib/provider/IdleSessionProvider.js | 9 +++--
web-v2/web/src/lib/provider/session.js | 4 +++
web-v2/web/src/lib/store/auth/index.js | 14 ++++++--
web-v2/web/src/lib/utils/axios/index.js | 42 ++++++++++++++++------
4 files changed, 54 insertions(+), 15 deletions(-)
diff --git a/web-v2/web/src/lib/provider/IdleSessionProvider.js
b/web-v2/web/src/lib/provider/IdleSessionProvider.js
index 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.js
index 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.js
index 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 login
oauthProviderFactory.reset()
diff --git a/web-v2/web/src/lib/utils/axios/index.js
b/web-v2/web/src/lib/utils/axios/index.js
index 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 sessionStorage
const user =
JSON.parse(window.sessionStorage.getItem('simpleAuthUser'))?.name
if (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 tokens
localStorage.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) {