For the complete documentation index, see llms.txt. This page is also available as Markdown.

Create an AtClient instance

The goal of authentication is to create a ready-to-use AtClient instance.

Now that you have properly instantiated an AtAuth instance and have either called .onboard or .authenticate, it is now time to obtain an AtClient instance

What you need

  • A successful AtOnboardingResponse or AtAuthResponse object, with response.session populated. See Onboarding a new Atsign or Authenticating an existing Atsign respectively on how to get those and what they are.

  • A local storage path to store AtClient data (into AtClientPreference.hiveStoragePath )

The minimal flow

From an AtOnboardingResponse success

import 'dart:io';

import 'package:at_auth/at_auth.dart';
import 'package:at_client/at_client.dart';

void main() async {
  const String atSign = '@alice';
  const String cramKey = 'the-cram-key';
  const String storagePath = '/home/alice/.atsign/storage/hive';

  final AtAuth atAuth = AtAuth.create();
  final AtOnboardingRequest request = AtOnboardingRequest(
    atSign,
    rootDomain: AtRootDomain.atsignDomain,
  );

  final AtOnboardingResponse response = await atAuth.onboard(request, cramKey);
  if (!response.isSuccessful) {
    stderr.writeln('Onboarding failed');
    exit(1);
  }

  final AtClientPreference preference = AtClientPreference()
    ..hiveStoragePath = storagePath;

  final AtClientManager atClientManager = await AtClientManager.getInstance()
      .fromAuthSession(response.session!, preference);

  final AtClient atClient = atClientManager.atClient;
  stdout.writeln('AtClient ready for $atSign');
}

From an AtAuthResponse success

Next

Put your first record: Building an AtKey.

Last updated