Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/web-pkg/src/composables/piniaStores/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PublicLinkType } from '@opencloud-eu/web-client'

export const useAuthStore = defineStore('auth', () => {
const accessToken = ref<string>()
const sessionId = ref<string>()
const idpContextReady = ref(false)
const userContextReady = ref(false)
const publicLinkToken = ref<string>()
Expand All @@ -14,6 +15,9 @@ export const useAuthStore = defineStore('auth', () => {
const setAccessToken = (value: string) => {
accessToken.value = value
}
const setSessionId = (value: string) => {
sessionId.value = value
}
const setIdpContextReady = (value: boolean) => {
idpContextReady.value = value
}
Expand All @@ -34,6 +38,7 @@ export const useAuthStore = defineStore('auth', () => {

const clearUserContext = () => {
setAccessToken(null)
setSessionId(null)
setIdpContextReady(null)
setUserContextReady(null)
}
Expand All @@ -49,6 +54,7 @@ export const useAuthStore = defineStore('auth', () => {

return {
accessToken,
sessionId,
idpContextReady,
userContextReady,
publicLinkToken,
Expand All @@ -57,6 +63,7 @@ export const useAuthStore = defineStore('auth', () => {
publicLinkContextReady,

setAccessToken,
setSessionId,
setIdpContextReady,
setUserContextReady,
setPublicLinkContext,
Expand Down
5 changes: 4 additions & 1 deletion packages/web-runtime/src/container/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ export const registerSSEEventListeners = ({
previewService,
configStore,
userStore,
authStore,
router
}: {
language: Language
Expand All @@ -873,6 +874,7 @@ export const registerSSEEventListeners = ({
previewService: PreviewService
configStore: ConfigStore
userStore: UserStore
authStore: AuthStore
router: Router
}): void => {
const resourceQueue = new PQueue({
Expand All @@ -897,7 +899,8 @@ export const registerSSEEventListeners = ({
previewService,
language,
router,
resourceQueue
resourceQueue,
authStore
} satisfies Partial<SseEventWrapperOptions>

clientService.sseAuthenticated.addEventListener(MESSAGE_TYPE.ITEM_RENAMED, (msg) =>
Expand Down
11 changes: 9 additions & 2 deletions packages/web-runtime/src/container/sse/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { SSEEventOptions } from './types'

export const onSSEBackchannelLogoutEvent = ({ router }: SSEEventOptions) => {
return router.push({ name: 'logout' })
export const onSSEBackchannelLogoutEvent = ({ router, authStore, sseData }: SSEEventOptions) => {
if (!sseData.sessionid) {
// No session ID in event: log out all clients per OIDC spec
return router.push({ name: 'logout' })
}

if (authStore.sessionId === sseData.sessionid) {
return router.push({ name: 'logout' })
}
}
5 changes: 4 additions & 1 deletion packages/web-runtime/src/container/sse/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod'
import {
AuthStore,
ClientService,
ConfigStore,
MessageStore,
Expand All @@ -19,7 +20,8 @@ export const eventSchema = z.object({
spaceid: z.string().optional(),
initiatorid: z.string().optional(),
etag: z.string().optional(),
affecteduserids: z.array(z.string()).optional().nullable()
affecteduserids: z.array(z.string()).optional().nullable(),
sessionid: z.string().optional()
})

export type EventSchemaType = z.infer<typeof eventSchema>
Expand All @@ -31,6 +33,7 @@ export interface SSEEventOptions {
messageStore: MessageStore
sharesStore: SharesStore
configStore: ConfigStore
authStore: AuthStore
clientService: ClientService
previewService: PreviewService
router: Router
Expand Down
1 change: 1 addition & 0 deletions packages/web-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export const bootstrapApp = async (configurationPath: string, appsReadyCallback:
userStore,
previewService,
configStore,
authStore,
router
})
}
Expand Down
5 changes: 5 additions & 0 deletions packages/web-runtime/src/services/auth/userManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ export class UserManager extends OidcUserManager {

this.authStore.setAccessToken(accessToken)

// Sync session ID from OIDC user profile for backchannel logout matching
void this.getUser().then((user) => {
this.authStore.setSessionId(user?.profile?.sid ?? null)
})

this.updateAccessTokenPromise = (async () => {
if (!fetchUserData) {
this.authStore.setIdpContextReady(true)
Expand Down
3 changes: 3 additions & 0 deletions packages/web-runtime/tests/unit/container/sse/files.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ClientService,
PreviewService,
useAuthStore,
useConfigStore,
useMessages,
useResourcesStore,
Expand Down Expand Up @@ -442,6 +443,7 @@ const getMocks = ({
const userStore = useUserStore()
const sharesStore = useSharesStore()
const configStore = useConfigStore()
const authStore = useAuthStore()
const clientService = mockDeep<ClientService>({ initiatorId: 'local1' })
const previewService = mockDeep<PreviewService>()
const router = mockDeep<Router>()
Expand All @@ -458,6 +460,7 @@ const getMocks = ({
userStore,
sharesStore,
configStore,
authStore,
clientService,
previewService,
resourceQueue,
Expand Down
3 changes: 3 additions & 0 deletions packages/web-runtime/tests/unit/container/sse/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createTestingPinia } from '@opencloud-eu/web-test-helpers'
import {
ClientService,
PreviewService,
useAuthStore,
useConfigStore,
useMessages,
useResourcesStore,
Expand Down Expand Up @@ -63,6 +64,7 @@ const getMocks = ({
const userStore = useUserStore()
const configStore = useConfigStore()
const sharesStore = useSharesStore()
const authStore = useAuthStore()
const clientService = mockDeep<ClientService>()
const previewService = mockDeep<PreviewService>()
const router = mockDeep<Router>()
Expand All @@ -77,6 +79,7 @@ const getMocks = ({
userStore,
sharesStore,
configStore,
authStore,
clientService,
previewService,
resourceQueue,
Expand Down
3 changes: 3 additions & 0 deletions packages/web-runtime/tests/unit/container/sse/shares.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ClientService,
eventBus,
PreviewService,
useAuthStore,
useConfigStore,
useMessages,
useResourcesStore,
Expand Down Expand Up @@ -700,6 +701,7 @@ const getMocks = ({
const userStore = useUserStore()
const configStore = useConfigStore()
userStore.user = mockDeep<User>({ id: '1' })
const authStore = useAuthStore()
const sharesStore = useSharesStore()
const clientService = mockDeep<ClientService>({ initiatorId: 'local1' })
const previewService = mockDeep<PreviewService>()
Expand Down Expand Up @@ -737,6 +739,7 @@ const getMocks = ({
userStore,
sharesStore,
configStore,
authStore,
clientService,
previewService,
resourceQueue,
Expand Down
Loading