Skip to content
Merged
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
3 changes: 2 additions & 1 deletion lib/solidpod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export 'src/solid/utils/misc.dart'
isDir,
logoutPod,
registerLogoutCacheCallback,
setAppDirName;
setAppDirName,
silentLogout;

/// Helper for deleting files and containers from a Solid POD

Expand Down
44 changes: 44 additions & 0 deletions lib/src/solid/utils/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import 'package:flutter/foundation.dart' show debugPrint;

import 'package:encrypter_plus/encrypter_plus.dart';
import 'package:fast_rsa/fast_rsa.dart' show KeyPair;
import 'package:http/http.dart' as http;
import 'package:intl/intl.dart';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'package:path/path.dart' as path;
Expand Down Expand Up @@ -518,6 +519,49 @@ Future<bool> logoutPod() async {
}
}

/// Clear all login state without opening a browser.
///
/// Performs the same cleanup as [logoutPod] but invalidates the IdP session
/// via a headless HTTP request rather than launching a visible browser
/// window. Use this when switching accounts or recovering from stale
/// credentials.

Future<bool> silentLogout() async {
try {
await KeyManager.clear();

final logoutUrl = await AuthDataManager.getLogoutUrl();
final authDataRemoved = await AuthDataManager.removeAuthData();

if (_onLogoutClearCaches != null) {
try {
await _onLogoutClearCaches!();
} on Object catch (e) {
debugPrint('silentLogout() cache callback failed (non-critical): $e');
}
}

// Best-effort IdP session invalidation via headless HTTP GET.

if (logoutUrl != null && logoutUrl.isNotEmpty) {
try {
await http.get(Uri.parse(logoutUrl));
} on Object catch (e) {
debugPrint('silentLogout() headless logout failed (non-critical): $e');
}
}

return authDataRemoved;
} on Object catch (e) {
debugPrint('silentLogout() CRITICAL: $e');
try {
await AuthDataManager.removeAuthData();
await KeyManager.clear();
} on Object catch (_) {}
return false;
}
}

/// Removes header and footer (which mess up the TTL format) from a PEM-formatted public key string.
///
/// This function takes a public key string, typically in PEM format, and removes
Expand Down
Loading