Onboarding

Authenticate the atClient with the atServer

Overview

Onboarding is the process of authenticating to the atServer using it's associated atSign. Instead of the traditional username and password, this process uses the atSign's secret cryptographic keys to perform authentication.

Setup Process

Depending on the SDK you are using, the process for onboarding varies.

Dart

In Dart we provide the at_onboarding_cli package which handles onboarding to the atServer via files stored in the ~/.atsign/keys directory

Manual Configuration

Installation

First add the package to your project

dart pub add at_onboarding_cli

Or add the package to your pubspec.yaml manually:

dependencies:
  at_onboarding_cli: ^1.3.0

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

© 2023 Atsign