From 40f33e5eb52e8a4641ec8d0f433da70aba6261e7 Mon Sep 17 00:00:00 2001 From: Dang Dat Date: Mon, 7 Sep 2026 11:25:21 +0700 Subject: [PATCH] Fall back to bearer-token flow when Cozy bridge is unavailable Addresses: 3946453617 https://github.com/linagora/tmail-flutter/pull/4804#discussion_r3946453617 --- .../data/datasource_impl/workplace_datasource_impl.dart | 7 +++---- workplace/lib/domain/exceptions/workplace_exceptions.dart | 3 --- .../extension/workplace_composer_attachment_extension.dart | 5 +++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/workplace/lib/data/datasource_impl/workplace_datasource_impl.dart b/workplace/lib/data/datasource_impl/workplace_datasource_impl.dart index 44ac62537..349555868 100644 --- a/workplace/lib/data/datasource_impl/workplace_datasource_impl.dart +++ b/workplace/lib/data/datasource_impl/workplace_datasource_impl.dart @@ -11,7 +11,6 @@ import '../model/workplace_intent_response.dart'; import '../bridge/cozy_bridge.dart'; import '../workplace_dio.dart'; import '../../domain/entity/workplace_intent.dart'; -import '../../domain/exceptions/workplace_exceptions.dart'; import '../../domain/entity/workplace_intent_config.dart'; class WorkplaceDataSourceImpl implements WorkplaceDataSource { @@ -33,9 +32,9 @@ class WorkplaceDataSourceImpl implements WorkplaceDataSource { }) async { final body = _buildIntentRequest(config); - // The container app already holds the stack session, so no bearer token. - if (CozyBridge.isSupported) { - if (!CozyBridge.isAvailable) throw WorkplaceBridgeUnavailableException(); + // The container app already holds the stack session, so no bearer token; + // fall back to the direct bearer-token flow when the bridge isn't usable. + if (CozyBridge.isSupported && CozyBridge.isAvailable) { final data = await CozyBridge.fetchJson( method: 'POST', path: '/intents', diff --git a/workplace/lib/domain/exceptions/workplace_exceptions.dart b/workplace/lib/domain/exceptions/workplace_exceptions.dart index 8276da47b..386758357 100644 --- a/workplace/lib/domain/exceptions/workplace_exceptions.dart +++ b/workplace/lib/domain/exceptions/workplace_exceptions.dart @@ -2,9 +2,6 @@ class WorkplaceCreateIntentException implements Exception {} class WorkplaceExchangeTokenException implements Exception {} -/// Web reaches Drive only through the container app's bridge. -class WorkplaceBridgeUnavailableException implements Exception {} - class DriveIntentErrorException implements Exception {} class DriveIntentPageLoadException implements Exception { diff --git a/workplace/lib/presentation/extension/workplace_composer_attachment_extension.dart b/workplace/lib/presentation/extension/workplace_composer_attachment_extension.dart index e4ee29abe..d11c20d51 100644 --- a/workplace/lib/presentation/extension/workplace_composer_attachment_extension.dart +++ b/workplace/lib/presentation/extension/workplace_composer_attachment_extension.dart @@ -58,9 +58,10 @@ class WorkplaceComposerAttachmentExtension implements ComposerAttachmentPlugin { required WorkplaceFilePickerConfigRequest filePickerConfig, }) async { // Mobile has no container app, so it authenticates against Drive directly; - // on web the bridge proxies through a session that already exists. + // on web the bridge proxies through a session that already exists, unless + // the bridge itself is unavailable, in which case fall back to direct auth. String? accessToken; - if (!CozyBridge.isSupported) { + if (!CozyBridge.isSupported || !CozyBridge.isAvailable) { final oidcToken = oidcTokenGetter(); if (oidcToken == null) throw StateError('OIDC token is unavailable'); accessToken = await _exchangeAccessToken(platformUrl, oidcToken);