Skip to content

Commit

Permalink
small improvements to example app
Browse files Browse the repository at this point in the history
  • Loading branch information
bardram committed Apr 19, 2024
1 parent 9a7576a commit ccf9063
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
39 changes: 19 additions & 20 deletions backends/carp_webservices/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:carp_webservices/carp_auth/carp_auth.dart';
import 'package:carp_core/carp_core.dart';
import 'package:oidc/oidc.dart';

// The URI of the CAWS server to connect to.
const String cawsUri = 'dev.carp.dk';
void main() {
CarpMobileSensing.ensureInitialized();
runApp(MyApp());
Expand Down Expand Up @@ -94,42 +96,40 @@ class _HomePageState extends State<HomePage> {

class AppBLoC {
ActiveParticipationInvitation? _invitation;
String? get studyId => _invitation?.studyId;
String? get studyDeploymentId => _invitation?.studyDeploymentId;

CarpApp? _app;
CarpApp? get app => _app;
Uri uri = Uri(
final Uri _uri = Uri(
scheme: 'https',
host: 'dev.carp.dk',
host: cawsUri,
pathSegments: [
'auth',
'realms',
'Carp',
],
);

bool get authenticated => currentUser != null;

CarpUser? currentUser;

late CarpApp mockCarpApp = CarpApp(
late CarpApp _app = CarpApp(
name: "CAWS @ DTU",
uri: uri.replace(pathSegments: []),
uri: _uri.replace(pathSegments: []),
);

late CarpAuthProperties authProperties = CarpAuthProperties(
authURL: uri,
late CarpAuthProperties _authProperties = CarpAuthProperties(
authURL: _uri,
clientId: 'studies-app',
redirectURI: Uri.parse('carp-studies-auth://auth'),
discoveryURL: uri.replace(pathSegments: [
...uri.pathSegments,
discoveryURL: _uri.replace(pathSegments: [
..._uri.pathSegments,
]),
);

CarpApp get app => _app;
CarpUser? currentUser;
bool get authenticated => currentUser != null;
String? get studyId => _invitation?.studyId;
String? get studyDeploymentId => _invitation?.studyDeploymentId;

Future<void> init() async {
await CarpAuthService().configure(authProperties);
CarpService().configure(mockCarpApp);
await CarpAuthService().configure(_authProperties);
CarpService().configure(app);
}

void dispose() async {}
Expand All @@ -141,8 +141,7 @@ class AppBLoC {
_invitation = await CarpParticipationService().getStudyInvitation(context);
print('CARP Study Invitation: $_invitation');
// check that the app has been updated to reflect the study id and deployment id
print(
'Study ID: ${app?.studyId}, Deployment ID: ${app?.studyDeploymentId}');
print('Study ID: ${app.studyId}, Deployment ID: ${app.studyDeploymentId}');
return _invitation;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class CarpAuthService extends CarpAuthBaseService {
return currentUser;
}

// // All other cases are treated as a failed attempt and throws an error
// All other cases are treated as a failed attempt and throws an error
_authEventController.add(AuthEvent.failed);
_currentUser = null;

Expand Down Expand Up @@ -181,7 +181,7 @@ class CarpAuthService extends CarpAuthBaseService {

/// Log out from this CARP service
///
/// opens a web view to clear cookies and end the session on the Identity Server.
/// Opens a web view to clear cookies and end the session on the Identity Server.
///
/// Use this if you used [authenticate] to authenticate.
Future<void> logout() async {
Expand Down

0 comments on commit ccf9063

Please sign in to comment.