Authentication
How to authenticate to an atServer
Dart
Package Installation
In Dart we provide the at_onboarding_cli package which handles onboarding to the atServer via files stored in the ~/.atsign/keys directory
Add the package to your project automatically using pub:
dart pub add at_onboarding_cli
Usage
Set up the preferences to onboard to the atServer.
AtOnboardingPreference atOnboardingConfig = AtOnboardingPreference()
..hiveStoragePath = '$homeDirectory/.$nameSpace/$fromAtsign/storage'
..namespace = nameSpace
..downloadPath = '$homeDirectory/.$nameSpace/files'
..isLocalStoreRequired = true
..commitLogPath = '$homeDirectory/.$nameSpace/$fromAtsign/storage/commitLog'
..rootDomain = rootDomain
..fetchOfflineNotifications = true
..atKeysFilePath = atsignFile
..atProtocolEmitted = Version(2, 0, 0);
Next get the onboardingService
AtOnboardingService onboardingService = AtOnboardingServiceImpl(
fromAtsign, atOnboardingConfig,
atServiceFactory: atServiceFactory);
Finally wait to be onboarded, this returns true once complete.
await onboardingService.authenticate();
This can be wrapped to check that the onboard was successful with the code snippet below.
bool onboarded = false;
Duration retryDuration = Duration(seconds: 3);
while (!onboarded) {
try {
stdout.write('\r\x1b[KConnecting ... ');
await Future.delayed(Duration(
milliseconds:
1000)); // Pause just long enough for the retry to be visible
onboarded = await onboardingService.authenticate();
} catch (exception) {
stdout.write(
'$exception. Will retry in ${retryDuration.inSeconds} seconds');
}
if (!onboarded) {
await Future.delayed(retryDuration);
}
}
stdout.writeln('Connected');
Last updated