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
6 changes: 4 additions & 2 deletions lib/solidpod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export 'src/solid/constants/predicates.dart';

/// Solid authentication function

export 'src/solid/authenticate.dart' show solidAuthenticate;
export 'src/solid/authenticate.dart'
show cancelSolidAuthenticate, isSolidAuthenticatePending, solidAuthenticate;

/// Status class to represent different function outputs

Expand Down Expand Up @@ -86,7 +87,8 @@ export 'src/solid/utils/exceptions.dart'
NotLoggedInException,
ResourceNotDecryptableException,
ResourceNotExistException,
SecurityKeyNotAvailableException;
SecurityKeyNotAvailableException,
SolidAuthCancelledException;

/// Includes common TTL conversion functions such as parseTTLMap.

Expand Down
20 changes: 20 additions & 0 deletions lib/src/solid/authenticate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

library;

import 'dart:async' show unawaited;
import 'dart:convert';

import 'package:flutter/material.dart';
Expand All @@ -41,6 +42,8 @@ import 'package:solid_auth/solid_auth.dart';
import 'package:solidpod/src/solid/api/rest_api.dart';
import 'package:solidpod/src/solid/utils/authdata_manager.dart'
show AuthDataManager;
import 'package:solidpod/src/solid/utils/exceptions.dart'
show SolidAuthCancelledException;
import 'package:solidpod/src/solid/utils/misc.dart'
show isUserLoggedIn, logoutPod;

Expand All @@ -53,6 +56,20 @@ final List<String> _scopes = <String>[
'webid', // web ID is necessary to get refresh token
];

/// Returns true while [solidAuthenticate] is awaiting the browser-based OAuth
/// flow.

bool isSolidAuthenticatePending() => isAuthenticatePending();

/// Aborts any in-flight [solidAuthenticate] call. Delegates to
/// `solid_auth.cancelAuthenticate()` which closes the local OAuth callback
/// server and errors the pending awaiter, so this caller unwinds with a
/// [SolidAuthCancelledException].

void cancelSolidAuthenticate() {
unawaited(cancelAuthenticate());
}

/// Asynchronously authenticate a user against a Solid server [serverId].
///
/// [serverId] is an issuer URI and is essential for the
Expand Down Expand Up @@ -85,6 +102,7 @@ Future<List<dynamic>?> solidAuthenticate(
// Authentication process for the POD issuer.

final issuerUri = await getIssuer(serverId);

authData = await authenticate(Uri.parse(issuerUri), _scopes, context);

// Validate authentication response before saving
Expand Down Expand Up @@ -130,6 +148,8 @@ Future<List<dynamic>?> solidAuthenticate(
final profData = utf8.decode(await getResource(profCardUrl));

return [authData, webId, profData];
} on AuthCancelledException catch (e) {
throw SolidAuthCancelledException(e.message);
} on Object catch (e) {
debugPrint('Solid Authenticate Failed: $e');
return null;
Expand Down
14 changes: 14 additions & 0 deletions lib/src/solid/utils/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,17 @@ class SecurityKeyNotAvailableException implements Exception {
@override
String toString() => 'SecurityKeyNotAvailableException: $message';
}

/// Thrown by [solidAuthenticate] when the in-flight authentication is aborted
/// by [cancelSolidAuthenticate]. Callers can catch this to distinguish a
/// deliberate cancellation from a genuine authentication failure such as a
/// network error.

class SolidAuthCancelledException implements Exception {
final String message;

SolidAuthCancelledException([this.message = 'Authentication was cancelled']);

@override
String toString() => 'SolidAuthCancelledException: $message';
}
4 changes: 4 additions & 0 deletions lib/src/solid/utils/init_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Future<void> clearPodStructureInitialised() async {
if (await secureStorage.containsKey(key: key)) {
await secureStorage.delete(key: key);
}
} on NotLoggedInException {
// Expected during account-switch flows where the caller logs out before
// clearing the flag. There is no user-specific key to delete, so this is
// a no-op rather than an error.
} on Object catch (e) {
debugPrint('clearPodStructureInitialised() failed: $e');
}
Expand Down
6 changes: 6 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ dev_dependencies:
flutter_lints: ^6.0.0
import_order_lint: ^0.2.2

dependency_overrides:
solid_auth:
git:
url: https://github.com/anusii/solid_auth.git
ref: tony/630_try_another_webid

flutter:
assets:
- assets/images/default_image.jpg
Expand Down
Loading