Skip to content
Closed
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
8 changes: 8 additions & 0 deletions lib/solid_auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ Future<Map> authenticate(
}

Future<bool> logout(logoutUrl) async {
// Clear platform-specific storage (Web: localStorage, Native: SharedPreferences)
try {
await authManager.clearLocalStorage();
} catch (e) {
debugPrint('logout() => Warning: Failed to clear storage: $e');
// Continue with logout flow even if storage clearing fails
}

Uri url = Uri.parse(logoutUrl);

if (await canLaunchUrl(url)) {
Expand Down
1 change: 1 addition & 0 deletions lib/src/auth_manager/auth_manager_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ abstract class AuthManager {
createAuthenticator(Client client, List<String> scopes, String dPopToken) {}
getOidcWeb() {}
userLogout(String logoutUrl) {}
Future<void> clearLocalStorage() async {}

// factory constructor to return the correct implementation.
factory AuthManager() => getAuthManager();
Expand Down
5 changes: 2 additions & 3 deletions lib/src/auth_manager/auth_manager_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
library;

import 'package:solid_auth/src/auth_manager/auth_manager_abstract.dart';
import 'package:solid_auth/src/auth_manager/native_auth_manager.dart';

AuthManager getAuthManager() => throw UnsupportedError(
'Cannot create a keyfinder without the packages dart:html or package:shared_preferences',
);
AuthManager getAuthManager() => NativeAuthManager();
79 changes: 79 additions & 0 deletions lib/src/auth_manager/native_auth_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/// Native Auth Manager for non-web platforms.
///
/// Copyright (C) 2025, Software Innovation Institute, ANU.
///
/// Licensed under the MIT License (the "License").
///
/// License: https://choosealicense.com/licenses/mit/.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
///
/// Authors: Anushka Vidanage
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be your name?

library;

import 'package:shared_preferences/shared_preferences.dart';
import 'package:solid_auth/src/auth_manager/auth_manager_abstract.dart';
import 'package:solid_auth/src/openid/src/openid.dart';

/// Auth manager implementation for native platforms (Linux, Windows, macOS, iOS, Android).
///
/// This provides platform-specific implementations using SharedPreferences
/// for storage operations on native platforms.
class NativeAuthManager implements AuthManager {
@override
String getKeyValue(String key) {
// Native platforms don't use localStorage
return '';
}

@override
getWebUrl() {
// Not applicable for native platforms
return null;
}

@override
createAuthenticator(Client client, List<String> scopes, String dPopToken) {
// Not applicable for native platforms
return null;
}

@override
getOidcWeb() {
// Not applicable for native platforms
return null;
}

@override
userLogout(String logoutUrl) {
// Native platforms handle logout through URL launcher, not window.open
}

@override
Future<void> clearLocalStorage() async {
try {
final prefs = await SharedPreferences.getInstance();
await prefs.clear();
} catch (e) {
throw Exception('Failed to clear SharedPreferences: $e');
}
}
}

AuthManager getAuthManager() => NativeAuthManager();
9 changes: 9 additions & 0 deletions lib/src/auth_manager/web_auth_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ class WebAuthManager implements AuthManager {
final child = window.open(logoutUrl, 'user_logout');
child!.close();
}

@override
Future<void> clearLocalStorage() async {
try {
windowLoc.localStorage.clear();
} catch (e) {
throw Exception('Failed to clear localStorage: $e');
}
}
}

AuthManager getAuthManager() => WebAuthManager();
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
url_launcher: ^6.3.1
uuid: ^4.5.1
web: ^1.1.1
shared_preferences: ^2.2.2

dev_dependencies:
flutter_lints: ^5.0.0
Expand Down