mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 16:04:20 +00:00
Fall back to bearer-token flow when Cozy bridge is unavailable
Addresses: 3946453617 https://github.com/linagora/tmail-flutter/pull/4804#discussion_r3946453617
This commit is contained in:
1 parent
9dbe6094c5
commit
40f33e5eb5
3 files changed
+6
-9
No files matched your search
@@ -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',
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user